rwsf::LogManager is a singleton providing a central point for accessing logger instances. Loggers can be registered with the rwsf::LogManager class, and can then be accessed from anywhere in the code.
- Note
- The LogManager class registers global Agent loggers, i.e., those used for service implementations, handlers, transports, and connectors. For clients and standalone servers, instead use the Web services logger. See the logging chapter in the Web Service Development Guide for more information.
Loggers are typically loaded on system start by parsing the logger configuration file (typically <installdir>\conf\loggers.xml
). This file defines a set of rwsf::Logger instances that are tied to specific logging implementations (such as LogFileWriter or LogLevelFilter). These defined rwsf::Logger instances are then added to the global LogManager and made available by name (or by default specification) through getLogger().
The following example demonstrates how to define two loggers, log1
and log2
, in the loggers.xml
file, then access those loggers from the code.
In loggers.xml:
<logger name="log1" class="rwsf_core.createLogLevelFilter">
<property name="logger" value="stdout"/>
<property name="filter" value="info"/>
</logger>
<logger name="log.file" class="rwsf_core.createFileLogger">
<property name="filename" value="logfile.txt"/>
<property name="formatter" value="rwsf_core.createLogTimeFormatter"/>
<property name="mode" value="overwrite"/>
</logger>
<logger name="log2" class="rwsf_core.createLogLevelFilter" default="true">
<property name="logger" value="log.file"/>
<property name="filter" value="debug"/>
</logger>
In C++ code:
The first line gets the log1
logger, which was declared as a stdout logger, filtered on logging level (i.e., only log() calls with logLevel values below the specified filter level get printed, info
in this case).
The second line gets the default logger (also defined as the log2
logger). This logger is set up as a standard filter (debug
in this case, so dev
messages won't get printed to the file) pointing to a file writer named log.file
. This log.file
logger is set to write to a file called logfile.txt
with a standard time format printed on each line. This file overwrites itself the next time the system is started.