limal::Logger Class Reference

LiMaL library logger class. More...

#include <Logger.hpp>

List of all members.

Public Types

typedef BLOCXX_NAMESPACE::ELogLevel ELogLevel
 Log level constants.

Public Member Functions

 Logger (const BLOCXX_NAMESPACE::String &component="")
 ~Logger ()
void logMessage (ELogLevel level, const BLOCXX_NAMESPACE::String &message, const char *filename=0, int fileline=-1, const char *methodname=0) const
void logMessage (const BLOCXX_NAMESPACE::String &category, const BLOCXX_NAMESPACE::String &message, const char *filename=0, int fileline=-1, const char *methodname=0) const
bool isEnabledFor (const ELogLevel level) const
bool isEnabledFor (const BLOCXX_NAMESPACE::String &category) const

Static Public Member Functions

static BLOCXX_NAMESPACE::LoggerRef createCerrLogger (const BLOCXX_NAMESPACE::String &component, const BLOCXX_NAMESPACE::Array< BLOCXX_NAMESPACE::String > &components, const BLOCXX_NAMESPACE::Array< BLOCXX_NAMESPACE::String > &categories, const BLOCXX_NAMESPACE::String &messageFormat)
 Create a new logger reference to a CerrLogger object.
static BLOCXX_NAMESPACE::LoggerRef createSyslogLogger (const BLOCXX_NAMESPACE::String &component, const BLOCXX_NAMESPACE::Array< BLOCXX_NAMESPACE::String > &components, const BLOCXX_NAMESPACE::Array< BLOCXX_NAMESPACE::String > &categories, const BLOCXX_NAMESPACE::String &messageFormat, const BLOCXX_NAMESPACE::String &identity, const BLOCXX_NAMESPACE::String &facility)
 Create a new logger reference to a SyslogLogger object.
static BLOCXX_NAMESPACE::LoggerRef createFileLogger (const BLOCXX_NAMESPACE::String &component, const BLOCXX_NAMESPACE::Array< BLOCXX_NAMESPACE::String > &components, const BLOCXX_NAMESPACE::Array< BLOCXX_NAMESPACE::String > &categories, const BLOCXX_NAMESPACE::String &messageFormat, const BLOCXX_NAMESPACE::String &filename, BLOCXX_NAMESPACE::UInt64 maxLogFileSize=0, BLOCXX_NAMESPACE::UInt32 maxBackupIndex=0)
 Create a new logger reference to a FileLogger object.
static BLOCXX_NAMESPACE::LoggerRef createNullLogger (const BLOCXX_NAMESPACE::String &component, const BLOCXX_NAMESPACE::Array< BLOCXX_NAMESPACE::String > &components, const BLOCXX_NAMESPACE::Array< BLOCXX_NAMESPACE::String > &categories, const BLOCXX_NAMESPACE::String &messageFormat)
 Create a new logger reference to a NullLogger object.
static bool setDefaultLogger (const BLOCXX_NAMESPACE::LoggerRef &ref)
static bool setThreadLogger (const BLOCXX_NAMESPACE::LoggerRef &ref)
static BLOCXX_NAMESPACE::LoggerRef getDefaultLogger ()
static BLOCXX_NAMESPACE::LoggerRef getCurrentLogger ()

Static Private Member Functions

static bool setDefaultFromLoggerRef (const BLOCXX_NAMESPACE::LoggerRef &ref)
static bool setThreadFromLoggerRef (const BLOCXX_NAMESPACE::LoggerRef &ref)
static BLOCXX_NAMESPACE::LoggerRef getDefaultAsLoggerRef ()
static BLOCXX_NAMESPACE::LoggerRef getCurrentAsLoggerRef ()

Private Attributes

BLOCXX_NAMESPACE::String m_component

Detailed Description

LiMaL library logger class.

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.

BloCxx Log Message Format

BloCxx supports configuration of the log message format using printf() style conversion specifiers.

Available conversion specifiers:

It is possible to change the minimum field width, the maximum field width and justification. The optional format modifier is placed between the percent sign and the conversion character.

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.


Member Typedef Documentation

typedef BLOCXX_NAMESPACE ::ELogLevel limal::Logger::ELogLevel

Log level constants.

Possible category names and their corresponding log levels are:

  •  "FATAL"    blocxx::E_FATAL_ERROR_LEVEL 
    
  •  "ERROR"    blocxx::E_ERROR_LEVEL       
    
  •  "INFO"     blocxx::E_INFO_LEVEL        
    
  •  "DEBUG"    blocxx::E_DEBUG_LEVEL       
    

Constructor & Destructor Documentation

limal::Logger::Logger ( const BLOCXX_NAMESPACE::String &  component = ""  ) 

Create a new Logger instance.

If no instance component is specified, then the default component of the registered logger is used instead.

Parameters:
component instance local component name
limal::Logger::~Logger (  ) 

Destroy a Logger instance


Member Function Documentation

static BLOCXX_NAMESPACE ::LoggerRef limal::Logger::createCerrLogger ( const BLOCXX_NAMESPACE::String &  component,
const BLOCXX_NAMESPACE::Array< BLOCXX_NAMESPACE::String > &  components,
const BLOCXX_NAMESPACE::Array< BLOCXX_NAMESPACE::String > &  categories,
const BLOCXX_NAMESPACE::String &  messageFormat 
) [static]

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);
Parameters:
component The default component name (application name).
components A filter list with component names that should be logged or "*" to log all components.
categories A filter list with category names that should be logged or "*" for all categories. Category names are "FATAL", "ERROR", "INFO", "DEBUG".
messageFormat A log message format string or empty string for default format defined by the logger.
Returns:
return A logger reference pointing to the CerrLogger.
static BLOCXX_NAMESPACE ::LoggerRef limal::Logger::createFileLogger ( const BLOCXX_NAMESPACE::String &  component,
const BLOCXX_NAMESPACE::Array< BLOCXX_NAMESPACE::String > &  components,
const BLOCXX_NAMESPACE::Array< BLOCXX_NAMESPACE::String > &  categories,
const BLOCXX_NAMESPACE::String &  messageFormat,
const BLOCXX_NAMESPACE::String &  filename,
BLOCXX_NAMESPACE::UInt64  maxLogFileSize = 0,
BLOCXX_NAMESPACE::UInt32  maxBackupIndex = 0 
) [static]

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);
Parameters:
component The default component name (application name).
components A filter list with component names that should be logged or "*" to log all components.
categories A filter list with category names that should be logged or "*" for all categories. Category names are "FATAL", "ERROR", "INFO", "DEBUG".
messageFormat A log message format string or empty string for default format defined by the logger.
filename The name of the log file.
maxLogFileSize The maximal file size in kb. 0 disables automatic log file rotation.
maxBackupIndex Maximal count of backup log files.
Returns:
return A logger reference pointing to the FileLogger.
static BLOCXX_NAMESPACE ::LoggerRef limal::Logger::createNullLogger ( const BLOCXX_NAMESPACE::String &  component,
const BLOCXX_NAMESPACE::Array< BLOCXX_NAMESPACE::String > &  components,
const BLOCXX_NAMESPACE::Array< BLOCXX_NAMESPACE::String > &  categories,
const BLOCXX_NAMESPACE::String &  messageFormat 
) [static]

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);
Parameters:
component The default component name (application name).
components A filter list with component names that should be logged or "*" to log all components.
categories A filter list with category names that should be logged or "*" for all categories. Category names are "FATAL", "ERROR", "INFO", "DEBUG".
messageFormat A log message format string or empty string for default format defined by the logger.
Returns:
return A logger reference pointing to the NullLogger.
static BLOCXX_NAMESPACE ::LoggerRef limal::Logger::createSyslogLogger ( const BLOCXX_NAMESPACE::String &  component,
const BLOCXX_NAMESPACE::Array< BLOCXX_NAMESPACE::String > &  components,
const BLOCXX_NAMESPACE::Array< BLOCXX_NAMESPACE::String > &  categories,
const BLOCXX_NAMESPACE::String &  messageFormat,
const BLOCXX_NAMESPACE::String &  identity,
const BLOCXX_NAMESPACE::String &  facility 
) [static]

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);
Parameters:
component The default component name (application name).
components A filter list with component names that should be logged or "*" to log all components.
categories A filter list with category names that should be logged or "*" for all categories. Category names are "FATAL", "ERROR", "INFO", "DEBUG".
messageFormat A log message format string or empty string for default format defined by the logger.
identity The syslog identity string.
facility The syslog facility to use ("user", "daemon", ...)
Returns:
return A logger reference pointing to the SyslogLogger.
static BLOCXX_NAMESPACE ::LoggerRef limal::Logger::getCurrentAsLoggerRef (  )  [static, private]

Referenced by getCurrentLogger().

static BLOCXX_NAMESPACE ::LoggerRef limal::Logger::getCurrentLogger (  )  [inline, static]

Get a copy of the per thread logger (LoggerRef) or if not set, the default one.

Returns:
a LoggerRef to the current logger

References getCurrentAsLoggerRef().

static BLOCXX_NAMESPACE ::LoggerRef limal::Logger::getDefaultAsLoggerRef (  )  [static, private]

Referenced by getDefaultLogger().

static BLOCXX_NAMESPACE ::LoggerRef limal::Logger::getDefaultLogger (  )  [inline, static]

Returns a copy of default logger (LoggerRef).

Returns:
a LoggerRef to the default logger

References getDefaultAsLoggerRef().

bool limal::Logger::isEnabledFor ( const BLOCXX_NAMESPACE::String &  category  )  const

Check if the logger is enabled for given category (named LogLevel, but not limited to).

Parameters:
category a log category
Returns:
true if enabled or false
bool limal::Logger::isEnabledFor ( const ELogLevel  level  )  const

Check if the logger is enabled for given level.

Parameters:
level a log level
Returns:
true if enabled or false
void limal::Logger::logMessage ( const BLOCXX_NAMESPACE::String &  category,
const BLOCXX_NAMESPACE::String &  message,
const char *  filename = 0,
int  fileline = -1,
const char *  methodname = 0 
) const

log a message using the specified category (a log level name) inclusive component name associated with the instance if not empty.

Parameters:
category a log category
message a log message
filename a file name (__FILE__)
fileline a line number (__LINE__)
methodname method name (__func__)
void limal::Logger::logMessage ( ELogLevel  level,
const BLOCXX_NAMESPACE::String &  message,
const char *  filename = 0,
int  fileline = -1,
const char *  methodname = 0 
) const

log a message with the specified level inclusive the component name associated with the instance if not empty.

Parameters:
level a log level
message a log message
filename a file name (__FILE__)
fileline a line number (__LINE__)
methodname method name (__func__)
static bool limal::Logger::setDefaultFromLoggerRef ( const BLOCXX_NAMESPACE::LoggerRef &  ref  )  [static, private]

Referenced by setDefaultLogger().

static bool limal::Logger::setDefaultLogger ( const BLOCXX_NAMESPACE::LoggerRef &  ref  )  [inline, static]

Set the default logger.

Parameters:
ref Reference to the new logger
Returns:
true if the logger was successfully set, false if ref doesn't contain any logger.

References setDefaultFromLoggerRef().

static bool limal::Logger::setThreadFromLoggerRef ( const BLOCXX_NAMESPACE::LoggerRef &  ref  )  [static, private]

Referenced by setThreadLogger().

static bool limal::Logger::setThreadLogger ( const BLOCXX_NAMESPACE::LoggerRef &  ref  )  [inline, static]

Set a per thread logger that overrides the default one.

Parameters:
ref Reference to the new logger
Returns:
true if the logger was successfully set, false if ref doesn't contain any logger.
Exceptions:
AssertException if try to put the logger into a thread local storage area failed.

References setThreadFromLoggerRef().


Member Data Documentation

BLOCXX_NAMESPACE ::String limal::Logger::m_component [private]

The documentation for this class was generated from the following file:
Generated on Mon Jul 5 22:01:31 2010 for limal by  doxygen 1.6.3