cppcore
A small, portable C++ core library
Loading...
Searching...
No Matches
cppcore::Logger Class Referencefinal

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.

Detailed Description

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 ).

Definition at line 88 of file Logger.h.

Member Enumeration Documentation

◆ PrintMode

enum class cppcore::Logger::PrintMode
strong

Describes the mode for prints into the active log stream.

Enumerator
Invalid 

Invalid marker.

WithDateTime 

A dateTime string will put be in front of the entry.

WithoutDateTime 

No DateTime will be there.

Count 

Number of enums.

Definition at line 101 of file Logger.h.

◆ VerboseMode

enum class cppcore::Logger::VerboseMode
strong

Describes the verbose mode.

Enumerator
Invalid 

Invalid marker.

Normal 

Only warnings and errors will be logged.

Verbose 

Normal messages will be logged as well.

Debug 

All debug messages will be logged as well.

Trace 

Will enable the tracing.

Count 

Number of enums.

Definition at line 91 of file Logger.h.

Member Function Documentation

◆ create()

Logger * cppcore::Logger::create ( )
static

Creates the unique logger instance and returns a pointer showing to it.

Returns
The singleton pointer of the logger.

Definition at line 85 of file Logger.cpp.

Referenced by getInstance().

◆ debug()

void cppcore::Logger::debug ( const String & domain,
const String & msg )

Logs a debug message.

Parameters
[in]domainThe domain.
[in]msgThe message to log.

Definition at line 135 of file Logger.cpp.

References Debug, getVerboseMode(), print(), and Trace.

Referenced by cppcore::debugPrint().

◆ error()

void cppcore::Logger::error ( const String & domain,
const String & msg )

Logs a error message.

Parameters
[in]domainThe domain.
[in]msgThe message to log.

Definition at line 207 of file Logger.cpp.

References print().

Referenced by cppcore::errorPrint().

◆ fatal()

void cppcore::Logger::fatal ( const String & domain,
const String & msg )

Logs a fatal error message.

Parameters
[in]domainThe domain.
[in]msgThe message to log.

Definition at line 216 of file Logger.cpp.

References print().

Referenced by cppcore::fatalPrint().

◆ getInstance()

Logger * cppcore::Logger::getInstance ( )
static

returns the singleton instance pointer of the logger.

Returns
The singleton 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().

◆ getVerboseMode()

Logger::VerboseMode cppcore::Logger::getVerboseMode ( ) const

Returns the current severity of the logger.

Returns
The current severity.

Definition at line 120 of file Logger.cpp.

Referenced by debug(), info(), and trace().

◆ info()

void cppcore::Logger::info ( const String & domain,
const String & msg )

Logs an info message.

Parameters
[in]domainThe domain.
[in]msgThe message to log.

Definition at line 146 of file Logger.cpp.

References Debug, getVerboseMode(), Normal, print(), Trace, and Verbose.

Referenced by cppcore::infoPrint().

◆ kill()

void cppcore::Logger::kill ( )
static

Kills the only instance of the logger.

Definition at line 109 of file Logger.cpp.

Referenced by set().

◆ print()

void cppcore::Logger::print ( const String & message,
PrintMode mode = PrintMode::WithoutDateTime )

Logs a print message.

Parameters
[in]messageThe message to log.
[in]modeLogging 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().

◆ registerLogStream()

void cppcore::Logger::registerLogStream ( AbstractLogStream * pLogStream)

Registers a new log stream.

Parameters
[in]pLogStreamA pointer showing to the log stream.

Definition at line 225 of file Logger.cpp.

◆ set()

void cppcore::Logger::set ( Logger * logger)
static

Will set a user-defined logger instance.

Parameters
[in]loggerThe new logger instance.

Definition at line 93 of file Logger.cpp.

References kill().

◆ setVerboseMode()

void cppcore::Logger::setVerboseMode ( VerboseMode sev)

Set the severity of the logger.

Parameters
[in]sevThe new severity of the logger.
See also
Severity

Definition at line 116 of file Logger.cpp.

◆ trace()

void cppcore::Logger::trace ( const String & domain,
const String & msg )

Logs a trace message.

Parameters
[in]domainThe domain.
[in]msgThe message to log.

Definition at line 124 of file Logger.cpp.

References getVerboseMode(), print(), and Trace.

Referenced by cppcore::tracePrint().

◆ unregisterLogStream()

void cppcore::Logger::unregisterLogStream ( const AbstractLogStream * pLogStream)

Unregisters a registered log stream.

Parameters
[in]pLogStreamA pointer showing to the log stream.

Definition at line 233 of file Logger.cpp.

◆ warn()

void cppcore::Logger::warn ( const String & domain,
const String & msg )

Logs a warn message.

Parameters
[in]domainThe domain.
[in]msgThe message to log.

Definition at line 198 of file Logger.cpp.

References print().

Referenced by cppcore::warnPrint().


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