blocxx
|
Logging interface. More...
#include <Logger.hpp>
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 &) | |
Logger & | operator= (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. | |
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. | |
void | logWarning (const String &message, const char *filename=0, int fileline=-1, const char *methodname=0) const |
If getLogLevel() >= E_WARNING_LEVEL, Log info. | |
void | logInfo (const String &message, const char *filename=0, int fileline=-1, const char *methodname=0) const |
If getLogLevel() >= E_INFO_LEVEL, Log info. | |
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. | |
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. | |
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. | |
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. | |
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. | |
void | logMessage (const String &category, const String &message) const |
Log a message using the default component and specified category. | |
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. | |
void | logMessage (const LogMessage &message) const |
Log a message. | |
void | setDefaultComponent (const String &component) |
Sets the default component. | |
String | getDefaultComponent () const |
Gets the default component. | |
ELogLevel | getLogLevel () const |
void | setLogLevel (ELogLevel logLevel) |
Set the log level. | |
void | setLogLevel (const String &logLevel) |
Set the log level. | |
bool | categoryIsEnabled (const String &category) const |
Determine if the log category is enabled. | |
bool | levelIsEnabled (const ELogLevel level) const |
Check if the logger is enabled for given level. | |
bool | componentAndCategoryAreEnabled (const String &component, const String &category) const |
Determine if the component and category are both enabled. | |
Static Public Member Functions | |
static ELogLevel | stringToLogLevel (const String &logLevel) |
Convert a log level string to an enum value. | |
static String | logLevelToString (ELogLevel logLevel) |
Convert a log level enum to a string. | |
static const Logger & | asLogger (const Logger &lgr) |
Utility functions for backward compatibility with LoggerRef and the BLOCXX_LOG macros. | |
static const Logger & | asLogger (const LoggerRef &lgr) |
Static Public Attributes | |
static const GlobalString | STR_NONE_CATEGORY = BLOCXX_GLOBAL_STRING_INIT("NONE") |
static const GlobalString | STR_FATAL_CATEGORY = BLOCXX_GLOBAL_STRING_INIT("FATAL") |
static const GlobalString | STR_ERROR_CATEGORY = BLOCXX_GLOBAL_STRING_INIT("ERROR") |
static const GlobalString | STR_WARNING_CATEGORY = BLOCXX_GLOBAL_STRING_INIT("WARNING") |
static const GlobalString | STR_INFO_CATEGORY = BLOCXX_GLOBAL_STRING_INIT("INFO") |
static const GlobalString | STR_DEBUG_CATEGORY = BLOCXX_GLOBAL_STRING_INIT("DEBUG") |
static const GlobalString | STR_DEBUG2_CATEGORY = BLOCXX_GLOBAL_STRING_INIT("DEBUG2") |
static const GlobalString | STR_DEBUG3_CATEGORY = BLOCXX_GLOBAL_STRING_INIT("DEBUG3") |
static const GlobalString | STR_ALL_CATEGORY = BLOCXX_GLOBAL_STRING_INIT("ALL") |
static const GlobalString | STR_DEFAULT_COMPONENT = BLOCXX_GLOBAL_STRING_INIT("none") |
Protected Attributes | |
String | m_defaultComponent |
LogAppenderRef | m_appender |
ELogLevel | m_logLevel |
Private Member Functions | |
void | processLogMessage (const LogMessage &message) const |
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 86 of file Logger.hpp.
Definition at line 101 of file Logger.hpp.
BLOCXX_NAMESPACE::Logger::Logger | ( | const String & | defaultComponent = STR_DEFAULT_COMPONENT , |
const LogAppenderRef & | appender = LogAppenderRef() |
||
) |
defaultComponent | The component used for log messages (can be overridden by logMessage()) |
appender | The Appender which will receive log messages. If NULL, the result of LogAppender::getCurrentLogAppender() will be used. |
Definition at line 66 of file Logger.cpp.
References BLOCXX_ASSERT, BLOCXX_NAMESPACE::String::length(), and m_defaultComponent.
Referenced by clone().
defaultComponent | The component used for log messages (can be overridden my logMessage()) |
logLevel | The log level. All lower level log messages will be ignored. |
Definition at line 75 of file Logger.cpp.
References BLOCXX_ASSERT, BLOCXX_NAMESPACE::String::length(), and m_defaultComponent.
BLOCXX_NAMESPACE::Logger::Logger | ( | const Logger & | x | ) |
Definition at line 84 of file Logger.cpp.
BLOCXX_NAMESPACE::Logger::~Logger | ( | ) | [virtual] |
Definition at line 113 of file Logger.cpp.
Utility functions for backward compatibility with LoggerRef and the BLOCXX_LOG macros.
Definition at line 309 of file Logger.hpp.
Definition at line 313 of file Logger.hpp.
bool BLOCXX_NAMESPACE::Logger::categoryIsEnabled | ( | const String & | category | ) | const |
Determine if the log category is enabled.
Definition at line 329 of file Logger.cpp.
References m_appender.
LoggerRef BLOCXX_NAMESPACE::Logger::clone | ( | ) | const [virtual] |
Definition at line 119 of file Logger.cpp.
References Logger().
bool BLOCXX_NAMESPACE::Logger::componentAndCategoryAreEnabled | ( | const String & | component, |
const String & | category | ||
) | const |
Determine if the component and category are both enabled.
Definition at line 343 of file Logger.cpp.
References m_appender.
String BLOCXX_NAMESPACE::Logger::getDefaultComponent | ( | ) | const |
Gets the default component.
Definition at line 239 of file Logger.cpp.
References m_defaultComponent.
ELogLevel BLOCXX_NAMESPACE::Logger::getLogLevel | ( | ) | const [inline] |
Definition at line 253 of file Logger.hpp.
Referenced by BLOCXX_NAMESPACE::AppenderLogger::getLevel(), and levelIsEnabled().
bool BLOCXX_NAMESPACE::Logger::levelIsEnabled | ( | const ELogLevel | level | ) | const |
Check if the logger is enabled for given level.
Definition at line 336 of file Logger.cpp.
References getLogLevel().
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.
message | The string to log. |
filename | The file where the log statement was written. |
fileline | The line number of the file where the log statement was written. |
methodname | The 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.
Referenced by BLOCXX_NAMESPACE::ScopeLogger::~ScopeLogger().
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.
message | The string to log. |
filename | The file where the log statement was written. |
fileline | The line number of the file where the log statement was written. |
methodname | The 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.
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.
message | The string to log. |
filename | The file where the log statement was written. |
fileline | The line number of the file where the log statement was written. |
methodname | The 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.
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.
message | The string to log. |
filename | The file where the log statement was written. |
fileline | The line number of the file where the log statement was written. |
methodname | The method name where the log statement was written. |
Definition at line 136 of file Logger.cpp.
References BLOCXX_NAMESPACE::E_ERROR_LEVEL, m_defaultComponent, m_logLevel, processLogMessage(), and STR_ERROR_CATEGORY.
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.
message | The string to log. |
filename | The file where the log statement was written. |
fileline | The line number of the file where the log statement was written. |
methodname | The method name where the log statement was written. |
Definition at line 126 of file Logger.cpp.
References BLOCXX_NAMESPACE::E_FATAL_ERROR_LEVEL, m_defaultComponent, m_logLevel, processLogMessage(), and STR_FATAL_CATEGORY.
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.
message | The string to log. |
filename | The file where the log statement was written. |
fileline | The line number of the file where the log statement was written. |
methodname | The 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.
Convert a log level enum to a string.
logLevel |
Definition at line 302 of file Logger.cpp.
References BLOCXX_NAMESPACE::E_ALL_LEVEL, BLOCXX_NAMESPACE::E_DEBUG2_LEVEL, BLOCXX_NAMESPACE::E_DEBUG3_LEVEL, BLOCXX_NAMESPACE::E_DEBUG_LEVEL, BLOCXX_NAMESPACE::E_ERROR_LEVEL, BLOCXX_NAMESPACE::E_FATAL_ERROR_LEVEL, BLOCXX_NAMESPACE::E_INFO_LEVEL, BLOCXX_NAMESPACE::E_WARNING_LEVEL, STR_ALL_CATEGORY, STR_DEBUG2_CATEGORY, STR_DEBUG3_CATEGORY, STR_DEBUG_CATEGORY, STR_ERROR_CATEGORY, STR_FATAL_CATEGORY, STR_INFO_CATEGORY, STR_NONE_CATEGORY, and STR_WARNING_CATEGORY.
void BLOCXX_NAMESPACE::Logger::logMessage | ( | const LogMessage & | message | ) | const |
Log a message.
The current log level is ignored.
message | The message to log |
Definition at line 224 of file Logger.cpp.
References processLogMessage().
Log a message using the default component and specified category.
The current log level is ignored.
category | The category of the log message. |
message | The message to log |
Definition at line 210 of file Logger.cpp.
References m_defaultComponent, and processLogMessage().
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.
component | The component generating the log message. |
category | The category of the log message. |
message | The message to log |
Definition at line 196 of file Logger.cpp.
References processLogMessage().
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.
component | The component generating the log message. |
category | The category of the log message. |
message | The message to log |
filename | The file where the log statement was written. |
fileline | The line number of the file where the log statement was written. |
methodname | The method name where the log statement was written. |
Definition at line 203 of file Logger.cpp.
References processLogMessage().
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.
category | The category of the log message. |
message | The message to log |
filename | The file where the log statement was written. |
fileline | The line number of the file where the log statement was written. |
methodname | The method name where the log statement was written. |
Definition at line 217 of file Logger.cpp.
References m_defaultComponent, and processLogMessage().
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.
message | The string to log. |
filename | The file where the log statement was written. |
fileline | The line number of the file where the log statement was written. |
methodname | The method name where the log statement was written. |
Definition at line 146 of file Logger.cpp.
References BLOCXX_NAMESPACE::E_WARNING_LEVEL, m_defaultComponent, m_logLevel, processLogMessage(), and STR_WARNING_CATEGORY.
Definition at line 94 of file Logger.cpp.
References m_appender, m_defaultComponent, and m_logLevel.
void BLOCXX_NAMESPACE::Logger::processLogMessage | ( | const LogMessage & | message | ) | const [private] |
Definition at line 350 of file Logger.cpp.
References BLOCXX_ASSERT, BLOCXX_NAMESPACE::LogMessage::category, BLOCXX_NAMESPACE::LogMessage::component, BLOCXX_NAMESPACE::String::empty(), m_appender, and BLOCXX_NAMESPACE::LogMessage::message.
Referenced by logDebug(), logDebug2(), logDebug3(), logError(), logFatalError(), logInfo(), logMessage(), and logWarning().
void BLOCXX_NAMESPACE::Logger::setDefaultComponent | ( | const String & | component | ) |
Sets the default component.
This function is not thread safe.
component | The new default component |
Definition at line 231 of file Logger.cpp.
References BLOCXX_ASSERT, and m_defaultComponent.
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.
logLevel | the level as an enumeration value. |
Definition at line 246 of file Logger.cpp.
References m_logLevel.
Referenced by setLogLevel().
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.
logLevel | The 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 253 of file Logger.cpp.
References setLogLevel(), and stringToLogLevel().
Convert a log level string to an enum value.
E_FATAL_ERROR_LEVEL is returned if the string is unknown.
logLevel |
Definition at line 260 of file Logger.cpp.
References BLOCXX_NAMESPACE::E_ALL_LEVEL, BLOCXX_NAMESPACE::E_DEBUG2_LEVEL, BLOCXX_NAMESPACE::E_DEBUG3_LEVEL, BLOCXX_NAMESPACE::E_DEBUG_LEVEL, BLOCXX_NAMESPACE::E_ERROR_LEVEL, BLOCXX_NAMESPACE::E_FATAL_ERROR_LEVEL, BLOCXX_NAMESPACE::E_INFO_LEVEL, BLOCXX_NAMESPACE::E_NONE_LEVEL, BLOCXX_NAMESPACE::E_WARNING_LEVEL, BLOCXX_NAMESPACE::String::equalsIgnoreCase(), STR_ALL_CATEGORY, STR_DEBUG2_CATEGORY, STR_DEBUG3_CATEGORY, STR_DEBUG_CATEGORY, STR_ERROR_CATEGORY, STR_INFO_CATEGORY, STR_NONE_CATEGORY, and STR_WARNING_CATEGORY.
Referenced by setLogLevel().
void BLOCXX_NAMESPACE::Logger::swap | ( | Logger & | x | ) |
Definition at line 105 of file Logger.cpp.
References m_appender, m_defaultComponent, m_logLevel, BLOCXX_NAMESPACE::IntrusiveReference< T >::swap(), and BLOCXX_NAMESPACE::String::swap().
LogAppenderRef BLOCXX_NAMESPACE::Logger::m_appender [protected] |
Definition at line 323 of file Logger.hpp.
Referenced by categoryIsEnabled(), componentAndCategoryAreEnabled(), operator=(), processLogMessage(), swap(), and BLOCXX_NAMESPACE::AppenderLogger::~AppenderLogger().
String BLOCXX_NAMESPACE::Logger::m_defaultComponent [protected] |
Definition at line 322 of file Logger.hpp.
Referenced by getDefaultComponent(), logDebug(), logDebug2(), logDebug3(), logError(), logFatalError(), Logger(), logInfo(), logMessage(), logWarning(), operator=(), setDefaultComponent(), and swap().
ELogLevel BLOCXX_NAMESPACE::Logger::m_logLevel [protected] |
Definition at line 324 of file Logger.hpp.
Referenced by logDebug(), logDebug2(), logDebug3(), logError(), logFatalError(), logInfo(), logWarning(), operator=(), setLogLevel(), and swap().
const GlobalString BLOCXX_NAMESPACE::Logger::STR_ALL_CATEGORY = BLOCXX_GLOBAL_STRING_INIT("ALL") [static] |
Definition at line 98 of file Logger.hpp.
Referenced by logLevelToString(), and stringToLogLevel().
const GlobalString BLOCXX_NAMESPACE::Logger::STR_DEBUG2_CATEGORY = BLOCXX_GLOBAL_STRING_INIT("DEBUG2") [static] |
Definition at line 96 of file Logger.hpp.
Referenced by BLOCXX_NAMESPACE::SyslogAppender::doProcessLogMessage(), BLOCXX_NAMESPACE::LogAppender::LogAppender(), logDebug2(), logLevelToString(), and stringToLogLevel().
const GlobalString BLOCXX_NAMESPACE::Logger::STR_DEBUG3_CATEGORY = BLOCXX_GLOBAL_STRING_INIT("DEBUG3") [static] |
Definition at line 97 of file Logger.hpp.
Referenced by BLOCXX_NAMESPACE::SyslogAppender::doProcessLogMessage(), BLOCXX_NAMESPACE::LogAppender::LogAppender(), logDebug3(), logLevelToString(), and stringToLogLevel().
const GlobalString BLOCXX_NAMESPACE::Logger::STR_DEBUG_CATEGORY = BLOCXX_GLOBAL_STRING_INIT("DEBUG") [static] |
Definition at line 95 of file Logger.hpp.
Referenced by BLOCXX_NAMESPACE::SyslogAppender::doProcessLogMessage(), BLOCXX_NAMESPACE::LogAppender::LogAppender(), logDebug(), logLevelToString(), and stringToLogLevel().
const GlobalString BLOCXX_NAMESPACE::Logger::STR_DEFAULT_COMPONENT = BLOCXX_GLOBAL_STRING_INIT("none") [static] |
Definition at line 99 of file Logger.hpp.
const GlobalString BLOCXX_NAMESPACE::Logger::STR_ERROR_CATEGORY = BLOCXX_GLOBAL_STRING_INIT("ERROR") [static] |
Definition at line 92 of file Logger.hpp.
Referenced by BLOCXX_NAMESPACE::SyslogAppender::doProcessLogMessage(), BLOCXX_NAMESPACE::LogAppender::LogAppender(), logError(), logLevelToString(), and stringToLogLevel().
const GlobalString BLOCXX_NAMESPACE::Logger::STR_FATAL_CATEGORY = BLOCXX_GLOBAL_STRING_INIT("FATAL") [static] |
Definition at line 91 of file Logger.hpp.
Referenced by BLOCXX_NAMESPACE::SyslogAppender::doProcessLogMessage(), BLOCXX_NAMESPACE::LogAppender::LogAppender(), logFatalError(), and logLevelToString().
const GlobalString BLOCXX_NAMESPACE::Logger::STR_INFO_CATEGORY = BLOCXX_GLOBAL_STRING_INIT("INFO") [static] |
Definition at line 94 of file Logger.hpp.
Referenced by BLOCXX_NAMESPACE::SyslogAppender::doProcessLogMessage(), BLOCXX_NAMESPACE::LogAppender::LogAppender(), logInfo(), logLevelToString(), and stringToLogLevel().
const GlobalString BLOCXX_NAMESPACE::Logger::STR_NONE_CATEGORY = BLOCXX_GLOBAL_STRING_INIT("NONE") [static] |
Definition at line 90 of file Logger.hpp.
Referenced by logLevelToString(), and stringToLogLevel().
const GlobalString BLOCXX_NAMESPACE::Logger::STR_WARNING_CATEGORY = BLOCXX_GLOBAL_STRING_INIT("WARNING") [static] |
Definition at line 93 of file Logger.hpp.
Referenced by BLOCXX_NAMESPACE::SyslogAppender::doProcessLogMessage(), BLOCXX_NAMESPACE::LogAppender::LogAppender(), logLevelToString(), logWarning(), and stringToLogLevel().