EvEmu
0.8.4
11 September 2021
|
a small and simple logging system. More...
#include "LogNew.h"
Public Member Functions | |
NewLog () | |
Primary constructor, initializes logging. More... | |
NewLog (std::string logPath) | |
~NewLog () | |
Destructor, closes the logfile. More... | |
void | Initialize () |
void | InitializeLogging (std::string logPath) |
Initializes and sets the Log file path. More... | |
void | Log (const char *source, const char *fmt,...) |
Logs a message to file. More... | |
void | Error (const char *source, const char *fmt,...) |
Logs error message to console and file. More... | |
void | Warning (const char *source, const char *fmt,...) |
Logs a warning message to file. More... | |
void | White (const char *source, const char *fmt,...) |
Logs a message to console in white. More... | |
void | Green (const char *source, const char *fmt,...) |
Logs a message to console in green. More... | |
void | Blue (const char *source, const char *fmt,...) |
Logs a message to console in blue. More... | |
void | Magenta (const char *source, const char *fmt,...) |
Logs a message to console in magenta. More... | |
void | Yellow (const char *source, const char *fmt,...) |
Logs a message to console in yellow. More... | |
void | Cyan (const char *source, const char *fmt,...) |
Logs a message to console in cyan. More... | |
void | Debug (const char *source, const char *fmt,...) |
Logs a debug message to file and console. More... | |
bool | SetLogfile (const char *filename) |
Sets the logfile to be used. More... | |
bool | SetLogfile (FILE *file) |
Sets the logfile to be used. More... | |
void | SetTime (time_t time) |
Sets the log system time every main loop. More... | |
![]() | |
Singleton () | |
Primary constructor. More... | |
Protected Types | |
enum | Color { COLOR_DEFAULT, COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE, COLOR_COUNT } |
A convenience color enum. More... | |
Protected Member Functions | |
void | PrintMsg (Color color, char pfx, const char *source, const char *fmt, va_list ap) |
Prints a message. More... | |
void | PrintTime () |
Prints current time. More... | |
void | Print (const char *fmt,...) |
Prints a raw message. More... | |
void | PrintVa (const char *fmt, va_list ap) |
Prints a raw message. More... | |
void | SetColor (Color color) |
Sets the color of the output text. More... | |
void | SetLogfileDefault (std::string logPath) |
Sets the default logfile. More... | |
Protected Attributes | |
FILE * | mLogfile |
The active logfile. More... | |
time_t | mTime |
Current timestamp. More... | |
Mutex | mMutex |
Protection against concurrent log messages. More... | |
bool | m_initialized |
Static Protected Attributes | |
static const char *const | COLOR_TABLE [COLOR_COUNT] |
Color translation table. More... | |
![]() | |
static std::shared_ptr< NewLog > | mInstance |
Additional Inherited Members | |
![]() | |
static NewLog & | get () |
a small and simple logging system.
This class is designed to be a simple logging system that both logs to file and console regarding the settings.
|
protected |
A convenience color enum.
Definition at line 162 of file LogNew.h.
NewLog::NewLog | ( | ) |
Primary constructor, initializes logging.
Definition at line 48 of file LogNew.cpp.
References m_initialized, and SetLogfileDefault().
NewLog::NewLog | ( | std::string | logPath | ) |
Definition at line 60 of file LogNew.cpp.
References m_initialized, and SetLogfileDefault().
NewLog::~NewLog | ( | ) |
Destructor, closes the logfile.
Definition at line 74 of file LogNew.cpp.
References Debug(), and SetLogfile().
void NewLog::Blue | ( | const char * | source, |
const char * | fmt, | ||
... | |||
) |
Logs a message to console in blue.
[in] | source | is the source from where the message is printed. |
[in] | fmt | is the message itself. |
Definition at line 161 of file LogNew.cpp.
References COLOR_BLUE, and PrintMsg().
Referenced by Initialize().
void NewLog::Cyan | ( | const char * | source, |
const char * | fmt, | ||
... | |||
) |
Logs a message to console in cyan.
[in] | source | is the source from where the message is printed. |
[in] | fmt | is the message itself. |
Definition at line 141 of file LogNew.cpp.
References COLOR_CYAN, and PrintMsg().
void NewLog::Debug | ( | const char * | source, |
const char * | fmt, | ||
... | |||
) |
Logs a debug message to file and console.
Optimized out on a release build.
[in] | source | is the source from where the message is printed. |
[in] | fmt | is the message itself. |
Definition at line 191 of file LogNew.cpp.
References COLOR_WHITE, is_log_enabled, and PrintMsg().
Referenced by ~NewLog().
void NewLog::Error | ( | const char * | source, |
const char * | fmt, | ||
... | |||
) |
Logs error message to console and file.
[in] | source | is the source from where the message is printed. |
[in] | fmt | is the error message itself. |
Definition at line 121 of file LogNew.cpp.
References COLOR_RED, and PrintMsg().
void NewLog::Green | ( | const char * | source, |
const char * | fmt, | ||
... | |||
) |
Logs a message to console in green.
[in] | source | is the source from where the message is printed. |
[in] | fmt | is the message itself. |
Definition at line 151 of file LogNew.cpp.
References COLOR_GREEN, and PrintMsg().
void NewLog::Initialize | ( | ) |
Definition at line 82 of file LogNew.cpp.
References Blue().
void NewLog::InitializeLogging | ( | std::string | logPath | ) |
Initializes and sets the Log file path.
[in] | logPath | is the absolute or relative path where log files are to be stored |
Definition at line 88 of file LogNew.cpp.
References m_initialized, and SetLogfileDefault().
void NewLog::Log | ( | const char * | source, |
const char * | fmt, | ||
... | |||
) |
Logs a message to file.
[in] | source | is the source from where the message is printed. |
[in] | fmt | is the message itself. |
Definition at line 99 of file LogNew.cpp.
References COLOR_DEFAULT, and PrintMsg().
void NewLog::Magenta | ( | const char * | source, |
const char * | fmt, | ||
... | |||
) |
Logs a message to console in magenta.
[in] | source | is the source from where the message is printed. |
[in] | fmt | is the message itself. |
Definition at line 171 of file LogNew.cpp.
References COLOR_MAGENTA, and PrintMsg().
|
protected |
Prints a raw message.
This method only handles printing to all desired destinations (standard output and logfile at the moment).
[in] | fmt | The format string. |
[in] | ... | The arguments. |
Definition at line 269 of file LogNew.cpp.
References PrintVa().
Referenced by PrintMsg(), and PrintTime().
|
protected |
Prints a message.
This prints a generic message.
[in] | color | Color of the message. |
[in] | pfx | Single-character prefix/identificator. |
[in] | source | Origin of message. |
[in] | fmt | The format string. |
[in] | ap | The arguments. |
Definition at line 230 of file LogNew.cpp.
References COLOR_DEFAULT, COLOR_WHITE, m_initialized, mMutex, Print(), PrintTime(), PrintVa(), and SetColor().
Referenced by Blue(), Cyan(), Debug(), Error(), Green(), Log(), Magenta(), Warning(), White(), and Yellow().
|
protected |
Prints current time.
Definition at line 256 of file LogNew.cpp.
References localtime_r(), mMutex, mTime, Print(), and SetTime().
Referenced by PrintMsg().
|
protected |
Prints a raw message.
This method only handles printing to all desired destinations (standard output and logfile at the moment).
[in] | fmt | The format string. |
[in] | ap | The arguments. |
Definition at line 279 of file LogNew.cpp.
References mLogfile, mMutex, and va_copy.
Referenced by Print(), and PrintMsg().
|
protected |
Sets the color of the output text.
[in] | color | The new color of output text. |
Definition at line 302 of file LogNew.cpp.
References COLOR_COUNT, COLOR_TABLE, and mMutex.
Referenced by PrintMsg().
bool NewLog::SetLogfile | ( | const char * | filename | ) |
Sets the logfile to be used.
[in] | filename | A name of file. |
true | The new logfile was successfully opened. |
false | Failed to open the new logfile. |
Definition at line 203 of file LogNew.cpp.
References mMutex.
Referenced by SetLogfileDefault(), and ~NewLog().
bool NewLog::SetLogfile | ( | FILE * | file | ) |
Sets the logfile to be used.
Passed file is closed during destruction.
[in] | file | A handle to file. |
true | The new logfile was successfully opened. |
false | Failed to open the new logfile. |
Definition at line 219 of file LogNew.cpp.
References mLogfile, and mMutex.
|
protected |
Sets the default logfile.
Definition at line 315 of file LogNew.cpp.
References localtime_r(), mMutex, mTime, SetLogfile(), SetTime(), snprintf, and Warning().
Referenced by InitializeLogging(), and NewLog().
|
inline |
Sets the log system time every main loop.
[in] | time | is the timestamp. |
Definition at line 158 of file LogNew.h.
References mTime.
Referenced by PrintTime(), and SetLogfileDefault().
void NewLog::Warning | ( | const char * | source, |
const char * | fmt, | ||
... | |||
) |
Logs a warning message to file.
[in] | source | is the source from where the message is printed. |
[in] | fmt | is the message itself. |
Definition at line 131 of file LogNew.cpp.
References COLOR_YELLOW, and PrintMsg().
Referenced by SetLogfileDefault().
void NewLog::White | ( | const char * | source, |
const char * | fmt, | ||
... | |||
) |
Logs a message to console in white.
[in] | source | is the source from where the message is printed. |
[in] | fmt | is the message itself. |
Definition at line 109 of file LogNew.cpp.
References COLOR_WHITE, is_log_enabled, and PrintMsg().
void NewLog::Yellow | ( | const char * | source, |
const char * | fmt, | ||
... | |||
) |
Logs a message to console in yellow.
[in] | source | is the source from where the message is printed. |
[in] | fmt | is the message itself. |
Definition at line 181 of file LogNew.cpp.
References COLOR_YELLOW, and PrintMsg().
|
staticprotected |
Color translation table.
Definition at line 245 of file LogNew.h.
Referenced by SetColor().
|
protected |
Definition at line 233 of file LogNew.h.
Referenced by InitializeLogging(), NewLog(), and PrintMsg().
|
protected |
The active logfile.
Definition at line 227 of file LogNew.h.
Referenced by PrintVa(), and SetLogfile().
|
protected |
Protection against concurrent log messages.
Definition at line 231 of file LogNew.h.
Referenced by PrintMsg(), PrintTime(), PrintVa(), SetColor(), SetLogfile(), and SetLogfileDefault().
|
protected |
Current timestamp.
Definition at line 229 of file LogNew.h.
Referenced by PrintTime(), SetLogfileDefault(), and SetTime().