blocxx
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | Private Member Functions | List of all members
BLOCXX_NAMESPACE::Logger Class Reference

Logging interface. More...

#include <Logger.hpp>

Inheritance diagram for BLOCXX_NAMESPACE::Logger:
BLOCXX_NAMESPACE::IntrusiveCountableBase BLOCXX_NAMESPACE::AppenderLogger BLOCXX_NAMESPACE::CerrLogger BLOCXX_NAMESPACE::NullLogger

Public Types

enum  ELoggerErrorCodes { E_UNKNOWN_LOG_APPENDER_TYPE, E_INVALID_MAX_FILE_SIZE, E_INVALID_MAX_BACKUP_INDEX }
 

Public Member Functions

 Logger (const String &defaultComponent=STR_DEFAULT_COMPONENT, const LogAppenderRef &appender=LogAppenderRef())
 
 Logger (const String &defaultComponent, const ELogLevel logLevel)
 
 Logger (const Logger &)
 
Loggeroperator= (const Logger &)
 
void swap (Logger &x)
 
virtual ~Logger ()
 
virtual LoggerRef clone () const BLOCXX_DEPRECATED
 
void logFatalError (const String &message, const char *filename=0, int fileline=-1, const char *methodname=0) const
 Log message with a fatal error category and the default component. More...
 
void logError (const String &message, const char *filename=0, int fileline=-1, const char *methodname=0) const
 If getLogLevel() >= E_ERROR_LEVEL, Log message with an error category and the default component. More...
 
void logWarning (const String &message, const char *filename=0, int fileline=-1, const char *methodname=0) const
 If getLogLevel() >= E_WARNING_LEVEL, Log info. More...
 
void logInfo (const String &message, const char *filename=0, int fileline=-1, const char *methodname=0) const
 If getLogLevel() >= E_INFO_LEVEL, Log info. More...
 
void logDebug (const String &message, const char *filename=0, int fileline=-1, const char *methodname=0) const
 If getLogLevel() >= E_DEBUG_LEVEL, Log debug info. More...
 
void logDebug2 (const String &message, const char *filename=0, int fileline=-1, const char *methodname=0) const
 If getLogLevel() >= E_DEBUG2_LEVEL, Log debug info. More...
 
void logDebug3 (const String &message, const char *filename=0, int fileline=-1, const char *methodname=0) const
 If getLogLevel() >= E_DEBUG3_LEVEL, Log debug info. More...
 
void logMessage (const String &component, const String &category, const String &message) const
 Log a message using the specified component and category The current log level is ignored. More...
 
void logMessage (const String &component, const String &category, const String &message, const char *filename, int fileline, const char *methodname) const
 Log a message using the specified component and category The current log level is ignored. More...
 
void logMessage (const String &category, const String &message) const
 Log a message using the default component and specified category. More...
 
void logMessage (const String &category, const String &message, const char *filename, int fileline, const char *methodname) const
 Log a message using the default component and specified category. More...
 
void logMessage (const LogMessage &message) const
 Log a message. More...
 
void setDefaultComponent (const String &component)
 Sets the default component. More...
 
String getDefaultComponent () const
 Gets the default component. More...
 
ELogLevel getLogLevel () const
 
void setLogLevel (ELogLevel logLevel)
 Set the log level. More...
 
void setLogLevel (const String &logLevel)
 Set the log level. More...
 
bool categoryIsEnabled (const String &category) const
 Determine if the log category is enabled. More...
 
bool levelIsEnabled (const ELogLevel level) const
 Check if the logger is enabled for given level. More...
 
bool componentAndCategoryAreEnabled (const String &component, const String &category) const
 Determine if the component and category are both enabled. More...
 

Static Public Member Functions

static ELogLevel stringToLogLevel (const String &logLevel)
 Convert a log level string to an enum value. More...
 
static String logLevelToString (ELogLevel logLevel)
 Convert a log level enum to a string. More...
 
static const LoggerasLogger (const Logger &lgr)
 Utility functions for backward compatibility with LoggerRef and the BLOCXX_LOG macros. More...
 
static const LoggerasLogger (const LoggerRef &lgr)
 

Static Public Attributes

static const GlobalString STR_NONE_CATEGORY = { "NONE" , 0, {0, PTHREAD_MUTEX_INITIALIZER} }
 
static const GlobalString STR_FATAL_CATEGORY = { "FATAL" , 0, {0, PTHREAD_MUTEX_INITIALIZER} }
 
static const GlobalString STR_ERROR_CATEGORY = { "ERROR" , 0, {0, PTHREAD_MUTEX_INITIALIZER} }
 
static const GlobalString STR_WARNING_CATEGORY = { "WARNING" , 0, {0, PTHREAD_MUTEX_INITIALIZER} }
 
static const GlobalString STR_INFO_CATEGORY = { "INFO" , 0, {0, PTHREAD_MUTEX_INITIALIZER} }
 
static const GlobalString STR_DEBUG_CATEGORY = { "DEBUG" , 0, {0, PTHREAD_MUTEX_INITIALIZER} }
 
static const GlobalString STR_DEBUG2_CATEGORY = { "DEBUG2" , 0, {0, PTHREAD_MUTEX_INITIALIZER} }
 
static const GlobalString STR_DEBUG3_CATEGORY = { "DEBUG3" , 0, {0, PTHREAD_MUTEX_INITIALIZER} }
 
static const GlobalString STR_ALL_CATEGORY = { "ALL" , 0, {0, PTHREAD_MUTEX_INITIALIZER} }
 
static const GlobalString STR_DEFAULT_COMPONENT = { "none" , 0, {0, PTHREAD_MUTEX_INITIALIZER} }
 

Protected Attributes

String m_defaultComponent
 
LogAppenderRef m_appender
 
ELogLevel m_logLevel
 

Private Member Functions

void processLogMessage (const LogMessage &message) const
 

Additional Inherited Members

- Protected Member Functions inherited from BLOCXX_NAMESPACE::IntrusiveCountableBase
 IntrusiveCountableBase ()
 
 IntrusiveCountableBase (const IntrusiveCountableBase &)
 
IntrusiveCountableBaseoperator= (const IntrusiveCountableBase &)
 
virtual ~IntrusiveCountableBase ()
 

Detailed Description

Logging interface.

Used to output log messages. A Logger has a component, a log level and a LogAppenderRef. The component will be used for all log messages generated, unless another component is explicitly specified in a call to logMessage(). The AppenderRef is the target for log messages. The global LogAppenderRef will be retrieved via LogAppender::getCurrentLogAppender() if one is not passed to the constructor. An application may call LogAppender::setDefaultLogAppender() to set the global LogAppenderRef. The log level will be obtained from the appender by calling m_appender->getLogLevel().

Invariants:

Responsibilities:

Collaborators:

Thread safety: read/write, except for setDefaultComponent() and setLogLevel() which should only be called during initialization phase.

Copy semantics: Value

Exception safety: Strong

Definition at line 116 of file Logger.hpp.

Member Enumeration Documentation

◆ ELoggerErrorCodes

Enumerator
E_UNKNOWN_LOG_APPENDER_TYPE 
E_INVALID_MAX_FILE_SIZE 
E_INVALID_MAX_BACKUP_INDEX 

Definition at line 131 of file Logger.hpp.

Constructor & Destructor Documentation

◆ Logger() [1/3]

BLOCXX_NAMESPACE::Logger::Logger ( const String defaultComponent = STR_DEFAULT_COMPONENT,
const LogAppenderRef appender = LogAppenderRef() 
)
Parameters
defaultComponentThe component used for log messages (can be overridden by logMessage())
appenderThe Appender which will receive log messages. If NULL, the result of LogAppender::getCurrentLogAppender() will be used.

Definition at line 96 of file Logger.cpp.

◆ Logger() [2/3]

BLOCXX_NAMESPACE::Logger::Logger ( const String defaultComponent,
const ELogLevel  logLevel 
)
Parameters
defaultComponentThe component used for log messages (can be overridden my logMessage())
logLevelThe log level. All lower level log messages will be ignored.

Definition at line 105 of file Logger.cpp.

References m_appender, m_defaultComponent, m_logLevel, BLOCXX_NAMESPACE::IntrusiveReference< T >::swap(), BLOCXX_NAMESPACE::String::swap(), and BLOCXX_NAMESPACE::swap().

◆ Logger() [3/3]

BLOCXX_NAMESPACE::Logger::Logger ( const Logger x)

Definition at line 114 of file Logger.cpp.

◆ ~Logger()

BLOCXX_NAMESPACE::Logger::~Logger ( )
virtual

Definition at line 143 of file Logger.cpp.

References BLOCXX_NAMESPACE::E_WARNING_LEVEL, and m_logLevel.

Member Function Documentation

◆ asLogger() [1/2]

static const Logger& BLOCXX_NAMESPACE::Logger::asLogger ( const Logger lgr)
inlinestatic

Utility functions for backward compatibility with LoggerRef and the BLOCXX_LOG macros.

Definition at line 339 of file Logger.hpp.

◆ asLogger() [2/2]

static const Logger& BLOCXX_NAMESPACE::Logger::asLogger ( const LoggerRef lgr)
inlinestatic

Definition at line 343 of file Logger.hpp.

◆ categoryIsEnabled()

bool BLOCXX_NAMESPACE::Logger::categoryIsEnabled ( const String category) const

Determine if the log category is enabled.

Definition at line 359 of file Logger.cpp.

◆ clone()

LoggerRef BLOCXX_NAMESPACE::Logger::clone ( ) const
virtual

Definition at line 149 of file Logger.cpp.

References m_defaultComponent, processLogMessage(), and STR_WARNING_CATEGORY.

◆ componentAndCategoryAreEnabled()

bool BLOCXX_NAMESPACE::Logger::componentAndCategoryAreEnabled ( const String component,
const String category 
) const

Determine if the component and category are both enabled.

Definition at line 373 of file Logger.cpp.

◆ getDefaultComponent()

String BLOCXX_NAMESPACE::Logger::getDefaultComponent ( ) const

Gets the default component.

Returns
The default component

Definition at line 269 of file Logger.cpp.

◆ getLogLevel()

ELogLevel BLOCXX_NAMESPACE::Logger::getLogLevel ( ) const
inline
Returns
The current log level

Definition at line 283 of file Logger.hpp.

Referenced by BLOCXX_NAMESPACE::AppenderLogger::AppenderLogger().

◆ levelIsEnabled()

bool BLOCXX_NAMESPACE::Logger::levelIsEnabled ( const ELogLevel  level) const

Check if the logger is enabled for given level.

Definition at line 366 of file Logger.cpp.

◆ logDebug()

void BLOCXX_NAMESPACE::Logger::logDebug ( const String message,
const char *  filename = 0,
int  fileline = -1,
const char *  methodname = 0 
) const

If getLogLevel() >= E_DEBUG_LEVEL, Log debug info.

Parameters
messageThe string to log.
filenameThe file where the log statement was written.
filelineThe line number of the file where the log statement was written.
methodnameThe method name where the log statement was written.

Definition at line 196 of file Logger.cpp.

References processLogMessage().

◆ logDebug2()

void BLOCXX_NAMESPACE::Logger::logDebug2 ( const String message,
const char *  filename = 0,
int  fileline = -1,
const char *  methodname = 0 
) const

If getLogLevel() >= E_DEBUG2_LEVEL, Log debug info.

Parameters
messageThe string to log.
filenameThe file where the log statement was written.
filelineThe line number of the file where the log statement was written.
methodnameThe method name where the log statement was written.

Definition at line 206 of file Logger.cpp.

◆ logDebug3()

void BLOCXX_NAMESPACE::Logger::logDebug3 ( const String message,
const char *  filename = 0,
int  fileline = -1,
const char *  methodname = 0 
) const

If getLogLevel() >= E_DEBUG3_LEVEL, Log debug info.

Parameters
messageThe string to log.
filenameThe file where the log statement was written.
filelineThe line number of the file where the log statement was written.
methodnameThe method name where the log statement was written.

Definition at line 216 of file Logger.cpp.

References m_defaultComponent, and processLogMessage().

◆ logError()

void BLOCXX_NAMESPACE::Logger::logError ( const String message,
const char *  filename = 0,
int  fileline = -1,
const char *  methodname = 0 
) const

If getLogLevel() >= E_ERROR_LEVEL, Log message with an error category and the default component.

Parameters
messageThe string to log.
filenameThe file where the log statement was written.
filelineThe line number of the file where the log statement was written.
methodnameThe method name where the log statement was written.

Definition at line 166 of file Logger.cpp.

References BLOCXX_NAMESPACE::E_DEBUG_LEVEL, m_defaultComponent, m_logLevel, processLogMessage(), and STR_DEBUG_CATEGORY.

◆ logFatalError()

void BLOCXX_NAMESPACE::Logger::logFatalError ( const String message,
const char *  filename = 0,
int  fileline = -1,
const char *  methodname = 0 
) const

Log message with a fatal error category and the default component.

Parameters
messageThe string to log.
filenameThe file where the log statement was written.
filelineThe line number of the file where the log statement was written.
methodnameThe method name where the log statement was written.

Definition at line 156 of file Logger.cpp.

References BLOCXX_NAMESPACE::E_INFO_LEVEL, m_defaultComponent, m_logLevel, processLogMessage(), and STR_INFO_CATEGORY.

◆ logInfo()

void BLOCXX_NAMESPACE::Logger::logInfo ( const String message,
const char *  filename = 0,
int  fileline = -1,
const char *  methodname = 0 
) const

If getLogLevel() >= E_INFO_LEVEL, Log info.

Parameters
messageThe string to log.
filenameThe file where the log statement was written.
filelineThe line number of the file where the log statement was written.
methodnameThe method name where the log statement was written.

Definition at line 186 of file Logger.cpp.

References BLOCXX_NAMESPACE::E_DEBUG3_LEVEL, m_defaultComponent, m_logLevel, processLogMessage(), and STR_DEBUG3_CATEGORY.

◆ logLevelToString()

String BLOCXX_NAMESPACE::Logger::logLevelToString ( ELogLevel  logLevel)
static

Convert a log level enum to a string.

Parameters
logLevel
Returns
String

Definition at line 332 of file Logger.cpp.

◆ logMessage() [1/5]

void BLOCXX_NAMESPACE::Logger::logMessage ( const LogMessage message) const

Log a message.

The current log level is ignored.

Parameters
messageThe message to log

Definition at line 254 of file Logger.cpp.

References setLogLevel(), and stringToLogLevel().

◆ logMessage() [2/5]

void BLOCXX_NAMESPACE::Logger::logMessage ( const String category,
const String message 
) const

Log a message using the default component and specified category.

The current log level is ignored.

Parameters
categoryThe category of the log message.
messageThe message to log

Definition at line 240 of file Logger.cpp.

References m_defaultComponent.

◆ logMessage() [3/5]

void BLOCXX_NAMESPACE::Logger::logMessage ( const String category,
const String message,
const char *  filename,
int  fileline,
const char *  methodname 
) const

Log a message using the default component and specified category.

The current log level is ignored.

Parameters
categoryThe category of the log message.
messageThe message to log
filenameThe file where the log statement was written.
filelineThe line number of the file where the log statement was written.
methodnameThe method name where the log statement was written.

Definition at line 247 of file Logger.cpp.

References m_logLevel.

◆ logMessage() [4/5]

void BLOCXX_NAMESPACE::Logger::logMessage ( const String component,
const String category,
const String message 
) const

Log a message using the specified component and category The current log level is ignored.

Parameters
componentThe component generating the log message.
categoryThe category of the log message.
messageThe message to log

Definition at line 226 of file Logger.cpp.

◆ logMessage() [5/5]

void BLOCXX_NAMESPACE::Logger::logMessage ( const String component,
const String category,
const String message,
const char *  filename,
int  fileline,
const char *  methodname 
) const

Log a message using the specified component and category The current log level is ignored.

Parameters
componentThe component generating the log message.
categoryThe category of the log message.
messageThe message to log
filenameThe file where the log statement was written.
filelineThe line number of the file where the log statement was written.
methodnameThe method name where the log statement was written.

Definition at line 233 of file Logger.cpp.

◆ logWarning()

void BLOCXX_NAMESPACE::Logger::logWarning ( const String message,
const char *  filename = 0,
int  fileline = -1,
const char *  methodname = 0 
) const

If getLogLevel() >= E_WARNING_LEVEL, Log info.

Parameters
messageThe string to log.
filenameThe file where the log statement was written.
filelineThe line number of the file where the log statement was written.
methodnameThe method name where the log statement was written.

Definition at line 176 of file Logger.cpp.

References BLOCXX_NAMESPACE::E_DEBUG2_LEVEL, m_defaultComponent, m_logLevel, processLogMessage(), and STR_DEBUG2_CATEGORY.

◆ operator=()

Logger & BLOCXX_NAMESPACE::Logger::operator= ( const Logger x)

Definition at line 124 of file Logger.cpp.

◆ processLogMessage()

void BLOCXX_NAMESPACE::Logger::processLogMessage ( const LogMessage message) const
private

Definition at line 380 of file Logger.cpp.

Referenced by clone(), logDebug(), logDebug3(), logError(), logFatalError(), logInfo(), logWarning(), and swap().

◆ setDefaultComponent()

void BLOCXX_NAMESPACE::Logger::setDefaultComponent ( const String component)

Sets the default component.

This function is not thread safe.

Parameters
componentThe new default component

Definition at line 261 of file Logger.cpp.

References BLOCXX_NAMESPACE::E_DEBUG_LEVEL, BLOCXX_NAMESPACE::E_INFO_LEVEL, BLOCXX_NAMESPACE::String::equalsIgnoreCase(), STR_DEBUG_CATEGORY, and STR_INFO_CATEGORY.

◆ setLogLevel() [1/2]

void BLOCXX_NAMESPACE::Logger::setLogLevel ( const String logLevel)

Set the log level.

All lower level log messages will be ignored. This function is not thread safe.

Parameters
logLevelThe log level, valid values: { STR_FATAL_ERROR_CATEGORY, STR_ERROR_CATEGORY, STR_INFO_CATEGORY, STR_DEBUG_CATEGORY, STR_DEBUG2_CATEGORY, STR_DEBUG3_CATEGORY }. Case-insensitive. If logLevel is unknown, the level will be set to E_FATAL_ERROR_LEVEL

Definition at line 283 of file Logger.cpp.

References BLOCXX_NAMESPACE::E_WARNING_LEVEL.

◆ setLogLevel() [2/2]

void BLOCXX_NAMESPACE::Logger::setLogLevel ( ELogLevel  logLevel)

Set the log level.

All lower level log messages will be ignored. This function is not thread safe.

Parameters
logLevelthe level as an enumeration value.

Definition at line 276 of file Logger.cpp.

Referenced by logMessage().

◆ stringToLogLevel()

ELogLevel BLOCXX_NAMESPACE::Logger::stringToLogLevel ( const String logLevel)
static

Convert a log level string to an enum value.

E_FATAL_ERROR_LEVEL is returned if the string is unknown.

Parameters
logLevel
Returns
ELogLevel

Definition at line 290 of file Logger.cpp.

References BLOCXX_NAMESPACE::E_NONE_LEVEL.

Referenced by logMessage().

◆ swap()

void BLOCXX_NAMESPACE::Logger::swap ( Logger x)

Member Data Documentation

◆ m_appender

LogAppenderRef BLOCXX_NAMESPACE::Logger::m_appender
protected

Definition at line 353 of file Logger.hpp.

Referenced by Logger().

◆ m_defaultComponent

String BLOCXX_NAMESPACE::Logger::m_defaultComponent
protected

◆ m_logLevel

ELogLevel BLOCXX_NAMESPACE::Logger::m_logLevel
protected

Definition at line 354 of file Logger.hpp.

Referenced by logError(), logFatalError(), Logger(), logInfo(), logMessage(), logWarning(), swap(), and ~Logger().

◆ STR_ALL_CATEGORY

const GlobalString BLOCXX_NAMESPACE::Logger::STR_ALL_CATEGORY = { "ALL" , 0, {0, PTHREAD_MUTEX_INITIALIZER} }
static

Definition at line 128 of file Logger.hpp.

◆ STR_DEBUG2_CATEGORY

const GlobalString BLOCXX_NAMESPACE::Logger::STR_DEBUG2_CATEGORY = { "DEBUG2" , 0, {0, PTHREAD_MUTEX_INITIALIZER} }
static

Definition at line 126 of file Logger.hpp.

Referenced by logWarning().

◆ STR_DEBUG3_CATEGORY

const GlobalString BLOCXX_NAMESPACE::Logger::STR_DEBUG3_CATEGORY = { "DEBUG3" , 0, {0, PTHREAD_MUTEX_INITIALIZER} }
static

Definition at line 127 of file Logger.hpp.

Referenced by logInfo().

◆ STR_DEBUG_CATEGORY

const GlobalString BLOCXX_NAMESPACE::Logger::STR_DEBUG_CATEGORY = { "DEBUG" , 0, {0, PTHREAD_MUTEX_INITIALIZER} }
static

Definition at line 125 of file Logger.hpp.

Referenced by logError(), and setDefaultComponent().

◆ STR_DEFAULT_COMPONENT

const GlobalString BLOCXX_NAMESPACE::Logger::STR_DEFAULT_COMPONENT = { "none" , 0, {0, PTHREAD_MUTEX_INITIALIZER} }
static

Definition at line 129 of file Logger.hpp.

◆ STR_ERROR_CATEGORY

const GlobalString BLOCXX_NAMESPACE::Logger::STR_ERROR_CATEGORY = { "ERROR" , 0, {0, PTHREAD_MUTEX_INITIALIZER} }
static

Definition at line 122 of file Logger.hpp.

Referenced by swap().

◆ STR_FATAL_CATEGORY

const GlobalString BLOCXX_NAMESPACE::Logger::STR_FATAL_CATEGORY = { "FATAL" , 0, {0, PTHREAD_MUTEX_INITIALIZER} }
static

Definition at line 121 of file Logger.hpp.

◆ STR_INFO_CATEGORY

const GlobalString BLOCXX_NAMESPACE::Logger::STR_INFO_CATEGORY = { "INFO" , 0, {0, PTHREAD_MUTEX_INITIALIZER} }
static

Definition at line 124 of file Logger.hpp.

Referenced by logFatalError(), and setDefaultComponent().

◆ STR_NONE_CATEGORY

const GlobalString BLOCXX_NAMESPACE::Logger::STR_NONE_CATEGORY = { "NONE" , 0, {0, PTHREAD_MUTEX_INITIALIZER} }
static

Definition at line 120 of file Logger.hpp.

◆ STR_WARNING_CATEGORY

const GlobalString BLOCXX_NAMESPACE::Logger::STR_WARNING_CATEGORY = { "WARNING" , 0, {0, PTHREAD_MUTEX_INITIALIZER} }
static

Definition at line 123 of file Logger.hpp.

Referenced by clone().


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