libcdoc 0.1.8
libcdoc::ILogger Class Reference

Generic interface to implement a logger. More...

#include <ILogger.h>

Inherited by libcdoc::ConsoleLogger.

Public Types

enum  LogLevel {
  LEVEL_FATAL , LEVEL_ERROR , LEVEL_WARNING , LEVEL_INFO ,
  LEVEL_DEBUG , LEVEL_TRACE
}
 Log-level enumeration to indicate severity of the log message. More...
 

Public Member Functions

 ILogger ()
 
virtual ~ILogger ()
 
virtual void LogMessage (LogLevel level, std::string_view file, int line, std::string_view message)
 Logs given message with given severity, file name and line number.
 
LogLevel GetMinLogLevel () const noexcept
 Returns current minimum log level of the logger.
 
void SetMinLogLevel (LogLevel level) noexcept
 Sets minimum log level for the logger.
 

Static Public Member Functions

static int addLogger (ILogger *logger)
 Adds ILogger implementation to logging queue.
 
static ILoggerremoveLogger (int cookie)
 Removes logger's instance from the logging queue.
 
static ILoggergetLogger ()
 Returns global logger's instance.
 

Protected Attributes

LogLevel minLogLevel
 Minimum level of log messages to log.
 

Detailed Description

Generic interface to implement a logger.

Member Enumeration Documentation

◆ LogLevel

Log-level enumeration to indicate severity of the log message.

Enumerator
LEVEL_FATAL 

Most critical level. Application is about to abort.

LEVEL_ERROR 

Errors where functionality has failed or an exception have been caught.

LEVEL_WARNING 

Warnings about validation issues or temporary failures that can be recovered.

LEVEL_INFO 

Information that highlights progress or application lifetime events.

LEVEL_DEBUG 

Debugging the application behavior from internal events of interest.

LEVEL_TRACE 

Most verbose level. Used for development, NOP in production code.

Constructor & Destructor Documentation

◆ ILogger()

libcdoc::ILogger::ILogger ( )
inline

◆ ~ILogger()

virtual libcdoc::ILogger::~ILogger ( )
inlinevirtual

Member Function Documentation

◆ addLogger()

static int libcdoc::ILogger::addLogger ( ILogger logger)
static

Adds ILogger implementation to logging queue.

This function does not take ownership of the logger's instance. It is up to the caller to free the resources of the logger's instance and keep it alive until removed from the queue.

Parameters
loggerLogger's instance to be added.
Returns
Unique cookie identifying the logger's instance in the logging queue.

◆ getLogger()

static ILogger * libcdoc::ILogger::getLogger ( )
static

Returns global logger's instance.

Returns
Global logger's instance.

Referenced by libcdoc::LogFormat(), and libcdoc::LogFormat().

◆ GetMinLogLevel()

LogLevel libcdoc::ILogger::GetMinLogLevel ( ) const
inlinenoexcept

Returns current minimum log level of the logger.

Returns
Minimum log level.

◆ LogMessage()

virtual void libcdoc::ILogger::LogMessage ( LogLevel  level,
std::string_view  file,
int  line,
std::string_view  message 
)
inlinevirtual

Logs given message with given severity, file name and line number.

Parameters
levelSeverity of the log message.
fileFile name where the log message was recorded.
lineLine number in the file where the log message was recorded.
messageThe log message.

Every class implementing the ILogger interface must implement the member function. Default implementation does nothing.

Reimplemented in libcdoc::ConsoleLogger.

Referenced by libcdoc::LogFormat(), and libcdoc::LogFormat().

◆ removeLogger()

static ILogger * libcdoc::ILogger::removeLogger ( int  cookie)
static

Removes logger's instance from the logging queue.

Parameters
cookieUnique cookie returned by the add_logger function when the logger was added.
Returns
Pointer to ILogger object that is removed. It's up to user to free the resources.

◆ SetMinLogLevel()

void libcdoc::ILogger::SetMinLogLevel ( LogLevel  level)
inlinenoexcept

Sets minimum log level for the logger.

Parameters
levelminimum level to log.

Sets minimum level of log messages to log. For example, if the minimum log level is set to LogLevelInfo (default), then LogLevelFatal, LogLevelError, LogLevelWarning and LogLevelInfo messages are logged, but not LogLevelDebug or LogLevelTrace messages.

Member Data Documentation

◆ minLogLevel

LogLevel libcdoc::ILogger::minLogLevel
protected

Minimum level of log messages to log.

Referenced by libcdoc::ConsoleLogger::LogMessage().


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