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 Class Reference

Project NSCpp. More...

#include <LogChannel.h>

Inheritance diagram for LogChannel:
Channel

Public Member Functions

 LogChannel (const std::string &key, const std::string &logFilePrefix)
 Constructor of the LogChannel.
 
void run (std::stop_token st)
 Run method of the Channel, process the given events.
 
void log (const std::string &logEntry)
 Callback which can be used trough the group (based on this channel's key) by other channels.
 
- Public Member Functions inherited from Channel
 Channel (const std::string &key)
 Constructor of the Channel's class.
 
void setKey (const std::string &key)
 Defined the Channel's key.
 
const std::string & getKey ()
 Return the Channel's key.
 
void setState (ChannelState state)
 Change the state of the server.
 
void push (ClientData data)
 Add the given data at the end of the queue.
 
ClientData pull ()
 Pop the first data from the queue and return it.
 
bool available ()
 Return true if data is available inside the dataQueue, false otherwise.
 

Protected Member Functions

void getStream (const std::string &name)
 Used to load/create the log file.
 
void loadTime (std::stringstream &ss)
 Load in the given streamstring the current time in the right format, and change the log file if needed (the date changed).
 

Protected Attributes

std::chrono::system_clock::time_point today
 Today's date.
 
std::string prefix
 Log file's prefix.
 
std::ofstream stream
 Log file's stream.
 
std::shared_mutex mtx
 Mutex for the log callback.
 
- Protected Attributes inherited from Channel
std::string key
 This key must be unique on the server on which it is plugged.
 
std::queue< ClientDatadataQueue
 This queue is used to store (and read) the data send to the Channel by the Server.
 
ChannelState state
 Control if the channel is active or not.
 

Detailed Description

Project NSCpp.

Author
Thomas K/BIDI
Version
2.0

Constructor & Destructor Documentation

◆ LogChannel()

LogChannel::LogChannel ( const std::string & key,
const std::string & logFilePrefix )

Constructor of the LogChannel.

Parameters
keyChannel's key.
logFilePrefixPrefix given to the log files. (Every log file will have the .log extension)

Member Function Documentation

◆ getStream()

void LogChannel::getStream ( const std::string & name)
protected

Used to load/create the log file.

If the log file already exist it's load and new logs will be append, otherwise it is created.

The log file have the name logFilePrefix + currentData[Y-M-D] + ".log"

Parameters
nameLog file's name.

◆ loadTime()

void LogChannel::loadTime ( std::stringstream & ss)
protected

Load in the given streamstring the current time in the right format, and change the log file if needed (the date changed).

Parameters
ssStringstream in which the current time (up to the seconds) is loaded.

◆ log()

void LogChannel::log ( const std::string & logEntry)

Callback which can be used trough the group (based on this channel's key) by other channels.

Every Channels can call the LogChannel's group and send a message which will be logged.

Parameters
logEntryMessage you want to be logged.

◆ run()

void LogChannel::run ( std::stop_token st)
virtual

Run method of the Channel, process the given events.

Implements Channel.

Member Data Documentation

◆ mtx

std::shared_mutex LogChannel::mtx
protected

Mutex for the log callback.

◆ prefix

std::string LogChannel::prefix
protected

Log file's prefix.

◆ stream

std::ofstream LogChannel::stream
protected

Log file's stream.

◆ today

std::chrono::system_clock::time_point LogChannel::today
protected

Today's date.


The documentation for this class was generated from the following file: