NSCpp 2.0
NSCpp is a modern C++20 server/client framework designed to simplify network programming in C++. With robust support for both IPv4 and IPv6, as well as TCP and UDP communication protocols.
 
Loading...
Searching...
No Matches
LogChannel.h
Go to the documentation of this file.
1
6
7
8#ifndef _LOGCHANNEL_H
9#define _LOGCHANNEL_H
10
11#include "Channel.h"
12#include "Serializer.h"
13#include <iostream>
14#include <fstream>
15#include <format>
16#include <chrono>
17
18/*
19* NB : If you want to log the message send to the clients you can use the logging callback
20* of this Channel, register it inside a group and send your message in that group, it will
21* be automatically register in the log file
22*/
23
24class LogChannel: public Channel {
25public:
31 LogChannel(const std::string& key, const std::string& logFilePrefix);
32
36 void run(std::stop_token st);
37
43 void log(const std::string& logEntry);
44
45protected:
52 void getStream(const std::string& name);
53
58 void loadTime(std::stringstream& ss);
59
63 std::chrono::system_clock::time_point today;
64
68 std::string prefix;
69
73 std::ofstream stream;
74
78 std::shared_mutex mtx;
79};
80
81#endif //_LOGCHANNEL_H
Project NSCpp.
std::string key
This key must be unique on the server on which it is plugged.
Definition Channel.h:98
Channel(const std::string &key)
Constructor of the Channel's class.
void getStream(const std::string &name)
Used to load/create the log file.
std::shared_mutex mtx
Mutex for the log callback.
Definition LogChannel.h:78
void run(std::stop_token st)
Run method of the Channel, process the given events.
std::string prefix
Log file's prefix.
Definition LogChannel.h:68
std::chrono::system_clock::time_point today
Today's date.
Definition LogChannel.h:63
LogChannel(const std::string &key, const std::string &logFilePrefix)
Constructor of the LogChannel.
void log(const std::string &logEntry)
Callback which can be used trough the group (based on this channel's key) by other channels.
std::ofstream stream
Log file's stream.
Definition LogChannel.h:73
void loadTime(std::stringstream &ss)
Load in the given streamstring the current time in the right format, and change the log file if neede...