#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 | ||||
| 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 | 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 | 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) | |||
| 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. | ||||
| LoggerRef | clone () const | |||
| Make a copy of the derived instance. | ||||
| virtual | ~Logger () | |||
Static Public Member Functions | ||||
| static String | getConfigItem (const LoggerConfigMap &configItems, const String &itemName, const String &defRetVal=String()) | |||
| Get a value from a given LoggerConfigMap. | ||||
| static void | setConfigItem (LoggerConfigMap &configItems, const String &itemName, const String &value, EOverwritePreviousConfigItemFlag overwritePrevious=E_OVERWRITE_PREVIOUS_CONFIG_ITEM) | |||
| Set a value for a given item name in a given LoggerConfigMap. | ||||
| static blocxx::LoggerRef | getCurrentLogger () | |||
| Get a copy of the per thread LoggerRef or if not set, the default one. | ||||
| static blocxx::LoggerRef | getDefaultLogger () | |||
| Returns a copy of default LoggerRef. | ||||
| static bool | setDefaultLogger (const blocxx::LoggerRef &ref) | |||
| Set the default global logger. | ||||
| static bool | setThreadLogger (const blocxx::LoggerRef &ref) | |||
| Set a per thread Logger that overrides the default one. | ||||
Static Public Attributes | ||||
| static const String | STR_NONE_CATEGORY | |||
| static const String | STR_FATAL_CATEGORY | |||
| static const String | STR_ERROR_CATEGORY | |||
| static const String | STR_INFO_CATEGORY | |||
| static const String | STR_DEBUG_CATEGORY | |||
| static const String | STR_ALL_CATEGORY | |||
| static const String | STR_DEFAULT_COMPONENT | |||
Protected Member Functions | ||||
| Logger (const String &defaultComponent, const ELogLevel logLevel) | ||||
| ||||
| virtual void | doProcessLogMessage (const LogMessage &message) const =0 | |||
| Output the message. | ||||
| virtual bool | doCategoryIsEnabled (const String &category) const | |||
| Return whether logging is enabled for the category. | ||||
| virtual bool | doComponentAndCategoryAreEnabled (const String &component, const String &category) const | |||
| Return whether logging is enabled for the component and category. | ||||
| virtual LoggerRef | doClone () const =0 | |||
| Make a copy of the derived instance. | ||||
| Logger (const Logger &) | ||||
| Logger & | operator= (const Logger &) | |||
| void | swap (Logger &x) | |||
Private Member Functions | ||||
| void | processLogMessage (const LogMessage &message) const | |||
Private Attributes | ||||
| ELogLevel | m_logLevel | |||
| String | m_defaultComponent | |||
Used to output log messages. A Logger has a component and a log level. The component will be used for all log messages generated, unless another component explicitly specified in a call to logMessage().
Invariants:
Responsibilities:
Collaborators:
Thread safety: read/write, except for setDefaultComponent() and setLogLevel() which should only be called during initialization phase.
Copy semantics: Non-copyable
Exception safety: Strong
Definition at line 78 of file Logger.hpp.
Definition at line 90 of file Logger.hpp.
| BLOCXX_NAMESPACE::Logger::~Logger | ( | ) | [virtual] |
Definition at line 94 of file Logger.cpp.
| BLOCXX_NAMESPACE::Logger::Logger | ( | const String & | defaultComponent, | |
| const ELogLevel | logLevel | |||
| ) | [protected] |
| 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 99 of file Logger.cpp.
References BLOCXX_ASSERT, and m_defaultComponent.
| BLOCXX_NAMESPACE::Logger::Logger | ( | const Logger & | x | ) | [protected] |
Definition at line 326 of file Logger.cpp.
| String BLOCXX_NAMESPACE::Logger::getConfigItem | ( | const LoggerConfigMap & | configItems, | |
| const String & | itemName, | |||
| const String & | defRetVal = String() | |||
| ) | [static] |
Get a value from a given LoggerConfigMap.
| configItems | The LoggerConfigMap to get the value from. | |
| itemName | The name of the item to get the value for. | |
| defRetVal | If the item name is not found in the map, then this value will be returned. |
Definition at line 68 of file Logger.cpp.
References BLOCXX_NAMESPACE::Map< Key, T, Compare >::end(), BLOCXX_NAMESPACE::Map< Key, T, Compare >::find(), and i.
Referenced by BLOCXX_NAMESPACE::LogAppender::createLogAppender().
| void BLOCXX_NAMESPACE::Logger::setConfigItem | ( | LoggerConfigMap & | configItems, | |
| const String & | itemName, | |||
| const String & | value, | |||
| EOverwritePreviousConfigItemFlag | overwritePrevious = E_OVERWRITE_PREVIOUS_CONFIG_ITEM | |||
| ) | [static] |
Set a value for a given item name in a given LoggerConfigMap.
| configItems | The LoggerConfigMap to set the value in. | |
| itemName | The name of the item to set the value for. If This itemName is not in the map, it will be added. | |
| value | The value to set in the map for itemName. | |
| overwritePrevious | this can be one of the following: E_PRESERVE_PREVIOUS_CONFIG_ITEM: Don't modify the item if it is already in the map. E_OVERWRITE_PREVIOUS_CONFIG_ITEM: Modify the item if it is already in the map. This is the default behavior. |
Definition at line 80 of file Logger.cpp.
References BLOCXX_NAMESPACE::Map< Key, T, Compare >::end(), and BLOCXX_NAMESPACE::Map< Key, T, Compare >::find().
| LoggerRef BLOCXX_NAMESPACE::Logger::getCurrentLogger | ( | ) | [static] |
Get a copy of the per thread LoggerRef or if not set, the default one.
If neither setDefaultLogger() or setThreadLogger() has been called, the default logger will be set to a NullLogger, and then returned.
Definition at line 444 of file Logger.cpp.
References BLOCXX_NAMESPACE::callOnce(), BLOCXX_NAMESPACE::g_loggerKey, BLOCXX_NAMESPACE::g_onceGuard, getDefaultLogger(), and BLOCXX_NAMESPACE::initGuardAndKey().
| LoggerRef BLOCXX_NAMESPACE::Logger::getDefaultLogger | ( | ) | [static] |
Returns a copy of default LoggerRef.
If you want to log messages, you shouldn't call this function. Use getCurrentLogger() instead. If setDefaultLogger() hasn't been called, the default logger will be set to a NullLogger, and then returned.
Definition at line 429 of file Logger.cpp.
References BLOCXX_NAMESPACE::callOnce(), BLOCXX_NAMESPACE::g_defaultLogger, BLOCXX_NAMESPACE::g_mutexGuard, BLOCXX_NAMESPACE::g_onceGuard, and BLOCXX_NAMESPACE::initGuardAndKey().
Referenced by getCurrentLogger().
| bool BLOCXX_NAMESPACE::Logger::setDefaultLogger | ( | const blocxx::LoggerRef & | ref | ) | [static] |
Set the default global logger.
Definition at line 387 of file Logger.cpp.
References BLOCXX_NAMESPACE::callOnce(), BLOCXX_NAMESPACE::g_defaultLogger, BLOCXX_NAMESPACE::g_mutexGuard, BLOCXX_NAMESPACE::g_onceGuard, and BLOCXX_NAMESPACE::initGuardAndKey().
| bool BLOCXX_NAMESPACE::Logger::setThreadLogger | ( | const blocxx::LoggerRef & | ref | ) | [static] |
Set a per thread Logger that overrides the default one.
Definition at line 404 of file Logger.cpp.
References BLOCXX_ASSERTMSG, BLOCXX_NAMESPACE::callOnce(), BLOCXX_NAMESPACE::freeThreadLogger(), BLOCXX_NAMESPACE::g_loggerKey, BLOCXX_NAMESPACE::g_onceGuard, and BLOCXX_NAMESPACE::initGuardAndKey().
| 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 153 of file Logger.cpp.
References BLOCXX_NAMESPACE::E_FATAL_ERROR_LEVEL, m_defaultComponent, m_logLevel, processLogMessage(), and STR_FATAL_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 168 of file Logger.cpp.
References BLOCXX_NAMESPACE::E_ERROR_LEVEL, m_defaultComponent, m_logLevel, processLogMessage(), and STR_ERROR_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 182 of file Logger.cpp.
References BLOCXX_NAMESPACE::E_INFO_LEVEL, m_defaultComponent, m_logLevel, processLogMessage(), and STR_INFO_CATEGORY.
| 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 196 of file Logger.cpp.
References BLOCXX_NAMESPACE::E_DEBUG_LEVEL, m_defaultComponent, m_logLevel, processLogMessage(), and STR_DEBUG_CATEGORY.
| 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 210 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 220 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 233 of file Logger.cpp.
References m_defaultComponent, and 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 242 of file Logger.cpp.
References m_defaultComponent, and processLogMessage().
| 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 254 of file Logger.cpp.
References processLogMessage().
| 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 296 of file Logger.cpp.
References BLOCXX_ASSERT, and m_defaultComponent.
| String BLOCXX_NAMESPACE::Logger::getDefaultComponent | ( | ) | const |
Gets the default component.
Definition at line 305 of file Logger.cpp.
References m_defaultComponent.
| ELogLevel BLOCXX_NAMESPACE::Logger::getLogLevel | ( | ) | const [inline] |
Definition at line 257 of file Logger.hpp.
Referenced by BLOCXX_NAMESPACE::AppenderLogger::getLevel(), and levelIsEnabled().
| 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 312 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 }. Case-insensitive. If logLevel is unknown, the level will be set to E_FATAL_ERROR_LEVEL |
Definition at line 122 of file Logger.cpp.
References BLOCXX_NAMESPACE::E_ALL_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::String::equalsIgnoreCase(), setLogLevel(), STR_ALL_CATEGORY, STR_DEBUG_CATEGORY, STR_ERROR_CATEGORY, STR_INFO_CATEGORY, and STR_NONE_CATEGORY.
| bool BLOCXX_NAMESPACE::Logger::categoryIsEnabled | ( | const String & | category | ) | const |
Determine if the log category is enabled.
Definition at line 262 of file Logger.cpp.
References doCategoryIsEnabled().
Referenced by BLOCXX_NAMESPACE::AppenderLogger::doCategoryIsEnabled().
| bool BLOCXX_NAMESPACE::Logger::levelIsEnabled | ( | const ELogLevel | level | ) |
Check if the logger is enabled for given level.
Definition at line 460 of file Logger.cpp.
References getLogLevel().
| bool BLOCXX_NAMESPACE::Logger::componentAndCategoryAreEnabled | ( | const String & | component, | |
| const String & | category | |||
| ) | const |
Determine if the component and category are both enabled.
Definition at line 270 of file Logger.cpp.
References doComponentAndCategoryAreEnabled().
Referenced by BLOCXX_NAMESPACE::AppenderLogger::doComponentAndCategoryAreEnabled().
| LoggerRef BLOCXX_NAMESPACE::Logger::clone | ( | ) | const |
Make a copy of the derived instance.
Provided the derived class has a suitable copy constructor, an implementation of clone should simply be: LoggerRef DerivedLogger::doClone() const { return LoggerRef(new DerivedLogger(*this)); }
Definition at line 320 of file Logger.cpp.
References doClone().
| virtual void BLOCXX_NAMESPACE::Logger::doProcessLogMessage | ( | const LogMessage & | message | ) | const [protected, pure virtual] |
Output the message.
Calls will not be serialized, so the derived class' implementation must be thread safe.
Implemented in BLOCXX_NAMESPACE::AppenderLogger, BLOCXX_NAMESPACE::CerrLogger, and BLOCXX_NAMESPACE::NullLogger.
Referenced by processLogMessage().
| bool BLOCXX_NAMESPACE::Logger::doCategoryIsEnabled | ( | const String & | category | ) | const [protected, virtual] |
Return whether logging is enabled for the category.
Default implementation always returns true.
Reimplemented in BLOCXX_NAMESPACE::AppenderLogger.
Definition at line 288 of file Logger.cpp.
Referenced by categoryIsEnabled().
| bool BLOCXX_NAMESPACE::Logger::doComponentAndCategoryAreEnabled | ( | const String & | component, | |
| const String & | category | |||
| ) | const [protected, virtual] |
Return whether logging is enabled for the component and category.
Default implementation always returns true.
Reimplemented in BLOCXX_NAMESPACE::AppenderLogger.
Definition at line 279 of file Logger.cpp.
Referenced by componentAndCategoryAreEnabled().
| virtual LoggerRef BLOCXX_NAMESPACE::Logger::doClone | ( | ) | const [protected, pure virtual] |
Make a copy of the derived instance.
Provided the derived class has a suitable copy constructor, an implementation of clone should simply be: LoggerRef DerivedLogger::doClone() const { return LoggerRef(new DerivedLogger(*this)); }
Implemented in BLOCXX_NAMESPACE::AppenderLogger, BLOCXX_NAMESPACE::CerrLogger, and BLOCXX_NAMESPACE::NullLogger.
Referenced by clone().
| void BLOCXX_NAMESPACE::Logger::swap | ( | Logger & | x | ) | [protected] |
Definition at line 347 of file Logger.cpp.
References m_defaultComponent, m_logLevel, BLOCXX_NAMESPACE::String::swap(), and BLOCXX_NAMESPACE::swap().
| void BLOCXX_NAMESPACE::Logger::processLogMessage | ( | const LogMessage & | message | ) | const [private] |
Definition at line 110 of file Logger.cpp.
References BLOCXX_ASSERT, BLOCXX_NAMESPACE::LogMessage::category, BLOCXX_NAMESPACE::LogMessage::component, doProcessLogMessage(), BLOCXX_NAMESPACE::String::empty(), and BLOCXX_NAMESPACE::LogMessage::message.
Referenced by logDebug(), logError(), logFatalError(), logInfo(), and logMessage().
const String BLOCXX_NAMESPACE::Logger::STR_NONE_CATEGORY [static] |
const String BLOCXX_NAMESPACE::Logger::STR_FATAL_CATEGORY [static] |
Definition at line 83 of file Logger.hpp.
Referenced by BLOCXX_NAMESPACE::SyslogAppender::doProcessLogMessage(), BLOCXX_NAMESPACE::LogAppender::getLogLevel(), and logFatalError().
const String BLOCXX_NAMESPACE::Logger::STR_ERROR_CATEGORY [static] |
Definition at line 84 of file Logger.hpp.
Referenced by BLOCXX_NAMESPACE::SyslogAppender::doProcessLogMessage(), BLOCXX_NAMESPACE::LogAppender::getLogLevel(), logError(), and setLogLevel().
const String BLOCXX_NAMESPACE::Logger::STR_INFO_CATEGORY [static] |
Definition at line 85 of file Logger.hpp.
Referenced by BLOCXX_NAMESPACE::SyslogAppender::doProcessLogMessage(), BLOCXX_NAMESPACE::LogAppender::getLogLevel(), logInfo(), and setLogLevel().
const String BLOCXX_NAMESPACE::Logger::STR_DEBUG_CATEGORY [static] |
Definition at line 86 of file Logger.hpp.
Referenced by BLOCXX_NAMESPACE::SyslogAppender::doProcessLogMessage(), BLOCXX_NAMESPACE::LogAppender::getLogLevel(), logDebug(), and setLogLevel().
const String BLOCXX_NAMESPACE::Logger::STR_ALL_CATEGORY [static] |
const String BLOCXX_NAMESPACE::Logger::STR_DEFAULT_COMPONENT [static] |
Definition at line 88 of file Logger.hpp.
Definition at line 351 of file Logger.hpp.
Referenced by logDebug(), logError(), logFatalError(), logInfo(), operator=(), setLogLevel(), and swap().
Definition at line 352 of file Logger.hpp.
Referenced by getDefaultComponent(), logDebug(), logError(), logFatalError(), Logger(), logInfo(), logMessage(), operator=(), setDefaultComponent(), and swap().
1.5.3