5. Initializing the logger.

Before using the logger, you (may) initialize the logger using InitLogger(), it is better to do it at the beginning of the program for ex: main() or DllMain(). The example for this is can be found in the file main.cpp

Initializing the logger is not mandatory, if any of the log functions are called without initializing, then the default log destination is to console (stdout).

3.1 Logging to File

The Initialization can be done to log to a file
        tFileLoggerInitParams fileInitParams;
        // very important, memset to prevent breaks when new members are
        // added to tFileLoggerInitParams.
        memset(&fileInitParams,0,sizeof(tFileLoggerInitParams));
        fileInitParams.fileName = "log.log";
        InitLogger(LogToFile,&fileInitParams);
By default the file will be opened in write mode and all previous data will be removed. To open a file in append mode, use the following : example (append_test.cpp)
        tFileLoggerInitParams fileInitParams;
        // very important, memset to prevent breaks when new members are
        // added to tFileLoggerInitParams.
        memset(&fileInitParams,0,sizeof(tFileLoggerInitParams));
        fileInitParams.fileOpenMode = AppendMode;
        fileInitParams.fileName = "log.log";
        InitLogger(LogToFile,&fileInitParams);

3.2 Logging to console

The Initialization can be done to log to console.
        // the init argument can be either stdout or stderr.
        InitLogger(LogToConsole, stdout);

3.3 Logging to a socket

The Initialization can be done to log to socket.
        tSockLoggerInitParams sockInitParams;
        // very important, memset to prevent breaks when new members are
        // added to tSockLoggerInitParams.
        memset(&sockInitParams,0,sizeof(tSockLoggerInitParams));
        sockInitParams.server   = "192.168.2.3";
        sockInitParams.port             = 50007;
        InitLogger(LogToSocket,&sockInitParams);
See section 13. Log Server for more details.

3.4 Changing the log destination.

If the logger is already initialized and to change the log destination (for example, initially you were doing to a console, but during the course of execution, you decide to redirect the logs to a socket), then you can call InitLogger() again.



liblogger © 2007 - SourceForge.net Logo