#include <Logger.hpp>
Public Types | |
| typedef blocxx::ELogLevel | ELogLevel |
| Log level constants. | |
Public Member Functions | |
| Logger (const blocxx::String &component="") | |
| ~Logger () | |
| void | logMessage (ELogLevel level, const blocxx::String &message, const char *filename=0, int fileline=-1, const char *methodname=0) const |
| void | logMessage (const blocxx::String &category, const blocxx::String &message, const char *filename=0, int fileline=-1, const char *methodname=0) const |
| bool | isEnabledFor (const ELogLevel level) |
| bool | isEnabledFor (const blocxx::String &category) |
Static Public Member Functions | |
| static blocxx::LoggerRef | createCerrLogger (const blocxx::String &component, const blocxx::Array< blocxx::String > &components, const blocxx::Array< blocxx::String > &categories, const blocxx::String &messageFormat) |
| Create a new logger reference to a CerrLogger object. | |
| static blocxx::LoggerRef | createSyslogLogger (const blocxx::String &component, const blocxx::Array< blocxx::String > &components, const blocxx::Array< blocxx::String > &categories, const blocxx::String &messageFormat, const blocxx::String &identity, const blocxx::String &facility) |
| Create a new logger reference to a SyslogLogger object. | |
| static blocxx::LoggerRef | createFileLogger (const blocxx::String &component, const blocxx::Array< blocxx::String > &components, const blocxx::Array< blocxx::String > &categories, const blocxx::String &messageFormat, const blocxx::String &filename, blocxx::UInt64 maxLogFileSize=0, blocxx::UInt32 maxBackupIndex=0) |
| Create a new logger reference to a FileLogger object. | |
| static blocxx::LoggerRef | createNullLogger (const blocxx::String &component, const blocxx::Array< blocxx::String > &components, const blocxx::Array< blocxx::String > &categories, const blocxx::String &messageFormat) |
| Create a new logger reference to a NullLogger object. | |
| static bool | setDefaultLogger (const blocxx::LoggerRef &ref) |
| static bool | setThreadLogger (const blocxx::LoggerRef &ref) |
| static blocxx::LoggerRef | getDefaultLogger () |
| static blocxx::LoggerRef | getCurrentLogger () |
Private Attributes | |
| blocxx::String | m_component |
The LiMaL logger class provides several static functions allowing to create standard logger types (file, cerr, syslog), to set them as the global/default or per thread logger in the blocxx library as well as to retrieve them.
Each instance of the LiMaL logger contains a optional local component name, that is passed with every log message to the current logger and used instead of the default component name, that is set in the logger.
This allows to use different component names at different places of the application and/or library, e.g. each plugin logs messages using own component name.
The LiMaL logger instance can be used directly or with the LIMAL_LOG(), LIMAL_SLOG() and derived macros.
Available conversion specifiers:
%c The component (e.g. myapp) %d The date. May be followed by a date format specifier enclosed between braces. Examples: "%d{%H:%M:%S}" "%d{%d %b %Y %H:%M:%S}"
%F The file name %l The filename and line number. e.g. file.cpp(100) %L The line number %M The method name where the logging request was issued (only works on C++ compilers which support __PRETTY_FUNCTION__ or C99's __func__) %m The message %e The message as XML CDATA. This includes the "<![CDATA[" and ending "]]>" %n The platform dependent line separator character (\n) or characters (\r\n) %p Category, aka level, aka priority %r The number of milliseconds elapsed since the start of the application until the creation of the logging event %t The thread id %%%% The % character. \n The newline character \t The tab character \r The linefeed character \\ The \ character \x<hexDigits> The character represented in hexadecimal.The first optional format modifier is the left justification flag which is the minus (-) character. The optional minimum field width modifier follows. It is an integer that represents the minimum number of characters to output. If the data item requires fewer characters, it is padded with spaces on either the left or the right, according to the justification flag. If the data item is larger than the minimum field width, the field is expanded to accommodate the data.
The maximum field width modifier is designated by a period followed by a decimal constant. If the data item is longer than the maximum field, then the extra characters are removed from the beginning of the data item (by default), or from the end if the left justification flag was specified.
Examples:
Log4j TTCC layout:
"%r [%t] %-5p %c - %m"
Similar to TTCC, but with some fixed size fields:
"%-6r [%15.15t] %-5p %30.30c - %m"
The TTCC message format is defined in the blocxx::LogAppender::STR_TTCC_MESSAGE_FORMAT constant.
|
|
Log level constants. Possible category names and their corresponding log levels are:
|
|
|
Create a new Logger instance. If no instance component is specified, then the default component of the registered logger is used instead.
|
|
|
Destroy a Logger instance |
|
||||||||||||||||||||
|
Create a new logger reference to a CerrLogger object. A application can use this function to create a logger reference pointing to a CerrLogger. The resulting reference object can be passed to the setDefaultLogger() or setThreadLogger() methods.
blocxx::Array<blocxx::String> components; components.push_back("*"); blocxx::Array<blocxx::String> categories; categories.push_back("*"); blocxx::LoggerRef l = limal::Logger::createCerrLogger( "main", components, categories, "%r [%d] %p %c - %m" ); limal::Logger::setDefaultLogger(l); // or: //blocxx::Logger::setDefaultLogger(l);
|
|
||||||||||||||||||||||||||||||||
|
Create a new logger reference to a FileLogger object. A application can use this function to create a logger reference pointing to a FileLogger. The resulting reference object can be passed to the setDefaultLogger() or setThreadLogger() methods.
blocxx::Array<blocxx::String> components(1, "*"); blocxx::Array<blocxx::String> categories(1, "*"); blocxx::LoggerRef l = limal::Logger::createFileLogger( "main", components, categories, "%r [%d] %p %c - %m", "/var/log/limal.log", 1024, 2 ); limal::Logger::setDefaultLogger(l);
|
|
||||||||||||||||||||
|
Create a new logger reference to a NullLogger object. A application can use this function to create a logger reference pointing to a NullLogger. The resulting reference object can be passed to the setDefaultLogger() or setThreadLogger() methods.
blocxx::Array<blocxx::String> components(1, "*"); blocxx::Array<blocxx::String> categories(1, "*"); blocxx::LoggerRef l = limal::Logger::createNullLogger( "main", components, categories, "%r [%d] %p %c - %m" ); limal::Logger::setDefaultLogger(l);
|
|
||||||||||||||||||||||||||||
|
Create a new logger reference to a SyslogLogger object. A application can use this function to create a logger reference pointing to a SyslogLogger. The resulting reference object can be passed to the setDefaultLogger() or setThreadLogger() methods.
blocxx::Array<blocxx::String> components(1, "*"); blocxx::Array<blocxx::String> categories(1, "*"); blocxx::LoggerRef l = limal::Logger::createSyslogLogger( "main", components, categories, "%r [%d] %p %c - %m", "myApp", "user" ); limal::Logger::setDefaultLogger(l);
|
|
|
Get a copy of the per thread logger (LoggerRef) or if not set, the default one.
|
|
|
Returns a copy of default logger (LoggerRef).
|
|
|
Check if the logger is enabled for given category (named LogLevel, but not limited to).
|
|
|
Check if the logger is enabled for given level.
|
|
||||||||||||||||||||||||
|
log a message using the specified category (a log level name) inclusive component name associated with the instance if not empty.
|
|
||||||||||||||||||||||||
|
log a message with the specified level inclusive the component name associated with the instance if not empty.
|
|
|
Set the default logger.
|
|
|
Set a per thread logger that overrides the default one.
|
|
|
|
1.4.6