Main Page | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages | Examples

rdaLogger Class Reference

Defines a general API for message logging and allows to connect it to a system specific logging facility. More...

List of all members.

Public Types

enum  LogLevel {
  LOG_OFF = 0, LOG_ERROR = 10, LOG_WARNING = 20, LOG_INFO = 30,
  LOG_TRACE = 40, LOG_DEBUG = 90, LOG_ALL = 100
}
 Defines a set of standard logging levels that can be used to control logging output. More...


Public Member Functions

const char * getName ()
 Returns the name of this logger.

void error (const char *message)
 Logs an ERROR message.

void warning (const char *message)
 Logs a WARNING message.

void info (const char *message)
 Logs an INFO message.

void trace (const char *message)
 Logs a TRACE message.

void debug (const char *message)
 Logs a DEBUG message.

LogLevel getLevel ()
 Returns the log level maintained by this logger.

void setLevel (LogLevel level)
 Sets the log level maintained by this logger.

bool isLoggable (LogLevel level)
 Returns true if a message of the given level would actually be logged by this logger.

std::ostream & getErrorStream ()
 Returns a stream that can be used to emit error messages.

std::ostream & getWarningStream ()
 Returns a stream that can be used to emit warning messages.

std::ostream & getInfoStream ()
 Returns a stream that can be used to emit info messages.

std::ostream & getTraceStream ()
 Returns a stream that can be used to emit trace messages.

std::ostream & getDebugStream ()
 Returns a stream that can be used to emit debug messages.


Static Public Member Functions

bool stringToLevel (LogLevel &level, const char *levelString)
 Sets the level to a value corresponding to the specified string.

const char * levelToString (LogLevel level)
 Returns the string name for the specified level.

void printInfo ()
 Prints a list of all loggers with their current trace levels on the stdout.

void init (rdaLoggerFactory &factory)
 Initializes the logging API and connects it to a system specific logging mechanism.

void init ()
 Initializes the logging API and connects it to the RDA default logging mechanism.

bool initialized ()
 Returns true if the Logger has been initialized.

void destroy ()
 Destroys all loggers and the logger factory, and releases all related resources.

rdaLoggergetLogger (const char *name)
 Returns a logger identified by the name.

rdaLoggergetAuditLogger (const char *name)
 Returns an "audit" logger identified by the name.

LogLevel getDefaultLevel ()
 Returns the class default log level.

void setDefaultLevel (LogLevel level)
 Sets the class default log level.

void setLevels (LogLevel level)
 Sets the specified level in all loggers in the system.


Protected Member Functions

virtual void log (LogLevel level, const char *message)=0
 If the logger is currently enabled for the given message level then the specified message is forwarded to the log output.


Detailed Description

Defines a general API for message logging and allows to connect it to a system specific logging facility.

An application can create an arbitrary number of named rdaLogger objects, each logger can be used to log message for an application component or a specific activity in the application. Logger objects may be obtained by calls to the getLogger factory method.

 //
 // Get a logger for the "poller" subsystem
 //
 rdaLogger* pollerLog = rdaLogger::getLogger("poller");
 //
 // Get a logger to trace timing events
 //
 rdaLogger* timingLog = rdaLogger::getLogger("timing");

A logger can be used to log text messages at different levels . On each logging call the logger performs a check of the message level (e.g. ERROR or WARNING) against a log level maintained by the logger. If the message level is higher than the log level, the logging call returns immediately, otherwise the message will be forwarded to the log output.

 //
 // Enable ERROR, WARNING and INFO messages
 //
 pollerLog->setLevel(rdaLogger::LOG_INFO);
 //
 // This message will be not logged
 //
 pollerLog->debug("Entering Poller::init()");
 //
 // This message will be logged
 //
 pollerLog->info("Initializing poller");
 //
 // This message will be not logged
 //
 pollerLog->trace("Connecting to timing");
 //
 // This message will be logged
 //
 pollerLog->warning("Event source undefined, using default");
 //
 // This message will be logged
 //
 pollerLog->error("Can't connect to timing, exiting");

By default, rdaLogger sends messages to the standard output. This default behaviour can be modified, and the messages can be forwarded to a system specific logging mechanism: see rdaLoggerFactory for more details.

See also:
ThreadedLogger Documentation
Examples:

LogExample.cpp.


Member Enumeration Documentation

enum rdaLogger::LogLevel
 

Defines a set of standard logging levels that can be used to control logging output.

The levels are ordered: enabling logging at a given level also enables logging at all lower levels.

Enumeration values:
LOG_OFF  A special level that can be used to turn off logging.
LOG_ERROR  A message level indicating a serious problem.
LOG_WARNING  A message level indicating a potential problem.
LOG_INFO  A message level for information messages.
LOG_TRACE  A message level providing tracing information.
LOG_DEBUG  A message level providing highly detailed tracing information.
LOG_ALL  A special level which indicates that all messages shall be logged.


Member Function Documentation

void rdaLogger::destroy  )  [static]
 

Destroys all loggers and the logger factory, and releases all related resources.

All pointers to the logger objects stored in the application become invalid after this call.

Examples:
LogExample.cpp.

rdaLogger* rdaLogger::getAuditLogger const char *  name  )  [static]
 

Returns an "audit" logger identified by the name.

An "audit" logger is by default exactly the same as the one obtained by the getLogger method. If a specialization is provided, the obtained class should at least limit the possibilities of changing the LogLevel. Optionally, the log messages can be directed to a different destination, etc.

See also:
init(rdaLoggerFactory&)

init()

getLogger( const char* )

LogLevel rdaLogger::getDefaultLevel  )  [static]
 

Returns the class default log level.

See also:
getLogger

rdaLogger* rdaLogger::getLogger const char *  name  )  [static]
 

Returns a logger identified by the name.

If such a logger does not exist it will be created. Calls to this method with the same name will always return the same object.

If a new logger is created its log level will be set from the class default log level. The initial value of the default log level is set at the initialization time from the cmw.defaultLogLevel property. If the property is not defined then the initial value is LOG_OFF. The default level can be checked and changed at run time by calls to the getDefaultLevel and setDefaultLevel methods.

The logging API should be explicitely initialized before calling the getLogger method. The method checks if this has been done and, if not, implicitely activates the default logging mechanism.

See also:
init(rdaLoggerFactory&)

init()

Examples:
LogExample.cpp.

void rdaLogger::init  )  [static]
 

Initializes the logging API and connects it to the RDA default logging mechanism.

All log messages will be sent to the standard output.

Exceptions:
rdaInternalException thrown to indicate that the logging has already been intitialized.
Examples:
LogExample.cpp.

void rdaLogger::init rdaLoggerFactory factory  )  [static]
 

Initializes the logging API and connects it to a system specific logging mechanism.

The objects created by the specified factory will be used to log messages.

Exceptions:
rdaInternalException thrown to indicate that the logging has already been intitialized.
See also:
rdaLoggerFactory

const char* rdaLogger::levelToString LogLevel  level  )  [static]
 

Returns the string name for the specified level.

See also:
stringToLevel

virtual void rdaLogger::log LogLevel  level,
const char *  message
[protected, pure virtual]
 

If the logger is currently enabled for the given message level then the specified message is forwarded to the log output.

See also:
LogLevel

void rdaLogger::setDefaultLevel LogLevel  level  )  [static]
 

Sets the class default log level.

See also:
getLogger
Examples:
LogExample.cpp.

bool rdaLogger::stringToLevel LogLevel level,
const char *  levelString
[static]
 

Sets the level to a value corresponding to the specified string.

stringlevel
"OFF" LOG_OFF
"ERROR" LOG_ERROR
"WARNING" LOG_WARNING
"INFO" LOG_INFO
"TRACE"LOG_TRACE
"DEBUG"LOG_DEBUG
"ALL" LOG_ALL

Returns false and does not change the level if the argument string does not represent a LogLevel, otherwise returns true.

See also:
levelToString


The documentation for this class was generated from the following file:
RDA-2.3 documentation - 27 Jun 2007 - N.Trofimov