shawn::Logger Class Reference

Main logging class. More...

#include <logger.h>

List of all members.

Public Member Functions

construction / destruction
 Logger ()
virtual ~Logger ()


Detailed Description

Main logging class.

This class offers logging features to nearly every class in this simulation framework. There is a chance to use existing logging libraries like log4cxx or log4cplus, or the use of the integrated logging features (which just put everything to stdout).

On the one hand there are already many classes which support logging functions (to call by name: everything derived from Processor and all classes in the KeeperManaged hierarchy like a SimulationTask). On the other hand you are able to enable the logging functions yourself. Both ways are described below.


Setting up the right library

To chose your favorated logging library, you have to add one of the following lines to the shawn_config.h:

    #define HAVE_LOG4CXX
to enable log4cxx,
    #define HAVE_LOG4CPLUS
to enable log4cplus, or
    #define DISABLE_LOGGING
to disable logging completly (just the user-messages will be displayed and nothing of the logging stuff will be compiled, more precisely removed by preprocessor directives). If there is nothing written, the internal logging functions will be used.

Moreover, if you want to remove debugging or info messages completly, just write on (or both) of the following lines to your shwan_config.h:

    #define DISABLE_LOGLEVEL_DEBUG
    #define DISABLE_LOGLEVEL_INFO
The affected lines will will not be compiled.

Using logging functions

Using the logging functions is quite simple. There is an example in shawn/legacyapps/logging_demo/ where the standard logging functions are used. Moreover there are exemplary configuration files for use of log4cxx and log4cplus (namely log4cxx.cfg and log4cplus.cfg).

As mentioned above, logging is not hard to be used. There are six different logging levels, which are implemented as macros:

    USER( message )
    DEBUG( logger, message )
    INFO( logger, message )
    WARN( logger, message )
    ERROR( logger, message )
    FATAL( logger, message )

First, the USER macro is a simple output of the main user information (just like which iteration step is computed etc.) and should not be disabled. There is only the message needed, which is to be printed out.

The other levels, from debug to fatal, need two arguments: At first the logger which is used to print out the message and second the message itself. Normally, a class is derived from Logger and owns an own logger object, so that, e.g. in a processor, the user is able to just call

    DEBUG( logger(), "My message" )

Moreover there is the chance, particularly if a class is not derived from a Logger (and the user don't want to derive it from a Logger as described in next section), the user is allowed to take the logger object from another class, e.g. SimulationController:

    DEBUG( simulation_controller.logger(), "My message" )

Enable logging functions yourself

If you want to spend a class it's own logging functions, this is done in a few steps: At first you should include the header file of Logger as follows:

    #include "sys/logging/logger.h"
Second, you have to derive your class from the Logger:
       class MyClass
    #ifdef ENABLE_LOGGING
         : public Logger
    #endif
Third and last, but optional, you should set the name of the logger in constructor of your class as follows
    #ifdef ENABLE_LOGGING
       set_logger_name( "my_logger" );
    #endif
to identify it in later use. If you forget to name it, there will be a standard name given.

This mechanism had already been used in Processor, World, SimulationController and KeeperManaged, so that you could look at an working example.


Constructor & Destructor Documentation

shawn::Logger::Logger (  ) 

virtual shawn::Logger::~Logger (  )  [virtual]


The documentation for this class was generated from the following file:

Generated on Sun Feb 5 00:00:56 2012 for Shawn by  doxygen 1.5.6