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. | |
rdaLogger * | getLogger (const char *name) |
Returns a logger identified by the name. | |
rdaLogger * | getAuditLogger (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. |
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.
|
|
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.
|
|
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.
|
|
Returns the class default log level.
|
|
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.
|
|
Initializes the logging API and connects it to the RDA default logging mechanism. All log messages will be sent to the standard output.
|
|
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.
|
|
Returns the string name for the specified level.
|
|
If the logger is currently enabled for the given message level then the specified message is forwarded to the log output.
|
|
Sets the class default log level.
|
|
Sets the level to a value corresponding to the specified string.
Returns
|