Bayeux  3.4.1
Core Foundation library for SuperNEMO
Classes | Namespaces
logger.h File Reference

Utilities for logging information. More...

#include <iostream>
#include "boost/current_function.hpp"
#include <datatools/reflection_interface.h>
#include <datatools/detail/logger_macros.h>

Go to the source code of this file.

Classes

struct  datatools::logger
 Organise logging functionality under one roof. More...
 

Namespaces

 datatools
 The Bayeux/datatools library top-level namespace.
 

Detailed Description

Utilities for logging information.

Logging information from the progress of an application often requires finer granularity than offered by the standard library streams. Log messages should also record where they came from.

To help developers log messages, datatools supplies a very basic priority based logging system. This uses the standard iostreams under the hood, but messages are logged at one of 8 priority levels from most to least critical. A minimum priority may be set, with only messages at that priority or higher logged to the relevant iostream.

This minimum priority can be stored in a variable, allowing logging priority to be adjusted on an instance-by-instance basis as well as at global or class scope.

Helper macros are provided to provide logging at each level if a provided priority meets the minimum level. For example, to log an informational message, you could use:

...
DT_LOG_INFORMATION(prio_, "Information message");

Provided the variable prio_ meets the minimum priority for information messages to be logged, the message will be streamed to the relevant iostream. As can be seen, the prio_ variable supplied to the logging macro could come from any relevant source (global, function argument, class variable, instance variable and so on).