XLL+ Class Library (6.3)

Directing log events

Retrieving a logger pointer

Before you can start writing events to the log, you need to call Logger::getLogger to retrieve a pointer to a Logger object, using the name of the Logger through which you wish to route your logging events. Typically, the Logger pointer is acquired during initialization, by making the pointer a static member of the class being logged.

There only needs to be one statement of this kind for any class.

CopyC++
using namespace psl::log;

class MyClass {
protected:
    static LoggerPtr m_logger;
public:
    void DoSomething();
};

LoggerPtr MyClass::m_logger = Logger::getLogger(_T("MyClass"));

Note the use of the _T() macro for the string argument. If you use this technique, your code will compile and work in Unicode as well as in ANSI builds.

Hierarchy

The loggers are nodes in a hierarchy. Within the hierarchy a logger named x.y is considered to be a child of logger x, and a logger x.y.z is considered to be a child of logger x.y.

The root logger has no name, and is considered to be the parent of logger x, and all other loggers whose name does not include a period. The root logger can be acquired by calling Logger::getRootLogger(), and it is referred to in configuration files as log.rootLogger.

Any setting applied to a parent node will apply to all its descendents, uinless they have their own settings. Consider the following configuration file settings:

log.rootLogger=ERROR, F
log.X=TRACE
log.X.Y.Z=INFO

The logging levels resulting from these settings are:

Logger Level
Root ERROR
x TRACE
x.y TRACE (inherited from x)
x.y.z INFO

Note that if an intermediate parent node is not specified, it is assumed to exist. Thus if there are two loggers x.y.z and x, an intermediate logger x.y will be created, as the parent of logger x.y.z and the child of logger x.

Next: Using the logging macros >>