#include <logger.h>
Public Member Functions | |
construction / destruction | |
| Logger () | |
| virtual | ~Logger () |
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
#define HAVE_LOG4CPLUS
#define DISABLE_LOGGING
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
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"
class MyClass #ifdef ENABLE_LOGGING : public Logger #endif
#ifdef ENABLE_LOGGING set_logger_name( "my_logger" ); #endif
This mechanism had already been used in Processor, World, SimulationController and KeeperManaged, so that you could look at an working example.
| shawn::Logger::Logger | ( | ) |
| virtual shawn::Logger::~Logger | ( | ) | [virtual] |
1.5.6