Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

limal::Logger Class Reference

LiMaL library logger class. More...

#include <Logger.hpp>

List of all members.

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


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::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::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::LoggerRef limal::Logger::createCerrLogger const blocxx::String &  component,
const blocxx::Array< blocxx::String > &  components,
const blocxx::Array< blocxx::String > &  categories,
const blocxx::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);
 // or:
 //blocxx::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::LoggerRef limal::Logger::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
[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::LoggerRef limal::Logger::createNullLogger const blocxx::String &  component,
const blocxx::Array< blocxx::String > &  components,
const blocxx::Array< blocxx::String > &  categories,
const blocxx::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::LoggerRef limal::Logger::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
[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::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

static blocxx::LoggerRef limal::Logger::getDefaultLogger  )  [inline, static]
 

Returns a copy of default logger (LoggerRef).

Returns:
a LoggerRef to the default logger

bool limal::Logger::isEnabledFor const blocxx::String &  category  ) 
 

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  ) 
 

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::String &  category,
const blocxx::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::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::setDefaultLogger const blocxx::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.

static bool limal::Logger::setThreadLogger const blocxx::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.


Member Data Documentation

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


The documentation for this class was generated from the following file:
Generated on Tue Sep 13 01:57:19 2005 for limal by  doxygen 1.4.4