|
cppcore
A small, portable C++ core library
|
This class implements a simple logger. More...
#include <Logger.h>
Public Types | |
| enum class | VerboseMode { Invalid = -1 , Normal , Verbose , Debug , Trace , Count } |
| Describes the verbose mode. More... | |
| enum class | PrintMode { Invalid = -1 , WithDateTime , WithoutDateTime , Count } |
| Describes the mode for prints into the active log stream. More... | |
Public Member Functions | |
| void | setVerboseMode (VerboseMode sev) |
| Set the severity of the logger. | |
| VerboseMode | getVerboseMode () const |
| Returns the current severity of the logger. | |
| void | trace (const String &domain, const String &msg) |
| Logs a trace message. | |
| void | debug (const String &domain, const String &msg) |
| Logs a debug message. | |
| void | info (const String &domain, const String &msg) |
| Logs an info message. | |
| void | print (const String &message, PrintMode mode=PrintMode::WithoutDateTime) |
| Logs a print message. | |
| void | warn (const String &domain, const String &msg) |
| Logs a warn message. | |
| void | error (const String &domain, const String &msg) |
| Logs a error message. | |
| void | fatal (const String &domain, const String &msg) |
| Logs a fatal error message. | |
| void | registerLogStream (AbstractLogStream *pLogStream) |
| Registers a new log stream. | |
| void | unregisterLogStream (const AbstractLogStream *pLogStream) |
| Unregisters a registered log stream. | |
Static Public Member Functions | |
| static Logger * | create () |
| Creates the unique logger instance and returns a pointer showing to it. | |
| static void | set (Logger *logger) |
| Will set a user-defined logger instance. | |
| static Logger * | getInstance () |
| returns the singleton instance pointer of the logger. | |
| static void | kill () |
| Kills the only instance of the logger. | |
This class implements a simple logger.
The logger is implemented as a singleton. You can attach several log streams to it, which can be used to log the messages to several output channels like a window or a log file or something else. The granularity of the logged messages can be controlled by the severity of the logger. The supported modes are normal ( no debug and info messages ), verbose ( all messages will be logged ) and debug ( the debug messages will be logged as well, be careful with this option ).
|
strong |
|
strong |
|
static |
Creates the unique logger instance and returns a pointer showing to it.
Definition at line 85 of file Logger.cpp.
Referenced by getInstance().
Logs a debug message.
| [in] | domain | The domain. |
| [in] | msg | The message to log. |
Definition at line 135 of file Logger.cpp.
References Debug, getVerboseMode(), print(), and Trace.
Referenced by cppcore::debugPrint().
Logs a error message.
| [in] | domain | The domain. |
| [in] | msg | The message to log. |
Definition at line 207 of file Logger.cpp.
References print().
Referenced by cppcore::errorPrint().
Logs a fatal error message.
| [in] | domain | The domain. |
| [in] | msg | The message to log. |
Definition at line 216 of file Logger.cpp.
References print().
Referenced by cppcore::fatalPrint().
|
static |
returns the singleton instance pointer of the logger.
Definition at line 101 of file Logger.cpp.
References create().
Referenced by cppcore::debugPrint(), cppcore::errorPrint(), cppcore::fatalPrint(), cppcore::infoPrint(), cppcore::tracePrint(), and cppcore::warnPrint().
| Logger::VerboseMode cppcore::Logger::getVerboseMode | ( | ) | const |
Returns the current severity of the logger.
Definition at line 120 of file Logger.cpp.
Logs an info message.
| [in] | domain | The domain. |
| [in] | msg | The message to log. |
Definition at line 146 of file Logger.cpp.
References Debug, getVerboseMode(), Normal, print(), Trace, and Verbose.
Referenced by cppcore::infoPrint().
|
static |
Kills the only instance of the logger.
Definition at line 109 of file Logger.cpp.
Referenced by set().
| void cppcore::Logger::print | ( | const String & | message, |
| PrintMode | mode = PrintMode::WithoutDateTime ) |
Logs a print message.
| [in] | message | The message to log. |
| [in] | mode | Logging mode |
Definition at line 162 of file Logger.cpp.
References cppcore::TStringBase< T >::isEmpty(), cppcore::TStringBase< T >::size(), WithDateTime, and cppcore::AbstractLogStream::write().
Referenced by debug(), error(), fatal(), info(), trace(), and warn().
| void cppcore::Logger::registerLogStream | ( | AbstractLogStream * | pLogStream | ) |
Registers a new log stream.
| [in] | pLogStream | A pointer showing to the log stream. |
Definition at line 225 of file Logger.cpp.
|
static |
Will set a user-defined logger instance.
| [in] | logger | The new logger instance. |
Definition at line 93 of file Logger.cpp.
References kill().
| void cppcore::Logger::setVerboseMode | ( | VerboseMode | sev | ) |
Set the severity of the logger.
| [in] | sev | The new severity of the logger. |
Definition at line 116 of file Logger.cpp.
Logs a trace message.
| [in] | domain | The domain. |
| [in] | msg | The message to log. |
Definition at line 124 of file Logger.cpp.
References getVerboseMode(), print(), and Trace.
Referenced by cppcore::tracePrint().
| void cppcore::Logger::unregisterLogStream | ( | const AbstractLogStream * | pLogStream | ) |
Unregisters a registered log stream.
| [in] | pLogStream | A pointer showing to the log stream. |
Definition at line 233 of file Logger.cpp.
Logs a warn message.
| [in] | domain | The domain. |
| [in] | msg | The message to log. |
Definition at line 198 of file Logger.cpp.
References print().
Referenced by cppcore::warnPrint().