Centralized global and local logging facility working on streams like std::cout
.
More...
#include <ogdf/basic/Logger.h>
Public Types | |
enum class | Level { Minor , Medium , Default , High , Alarm , Force } |
supported log-levels from lowest to highest importance More... | |
enum class | LogMode { Global , GlobalLog , Log , Statistic } |
Local log-modes. More... | |
Public Member Functions | |
Logger () | |
creates a new Logger-object with LogMode::Global and local log-level equal globalLogLevel | |
Logger (Level level) | |
creates a new Logger-object with LogMode::Global and given local log-level | |
Logger (LogMode m) | |
creates a new Logger-object with given log-mode and local log-level equal globalLogLevel | |
Logger (LogMode m, Level level) | |
creates a new Logger-object with given log-mode and given local log-level | |
Usage | |
bool | is_lout (Level level=Level::Default) const |
returns true if such an lout command will result in text being printed | |
std::ostream & | lout (Level level=Level::Default) const |
stream for logging-output (local) | |
std::ostream & | sout () const |
stream for statistic-output (local) | |
std::ostream & | fout () const |
stream for forced output (local) | |
Local | |
Level | localLogLevel () const |
gives the local log-level | |
void | localLogLevel (Level level) |
sets the local log-level | |
LogMode | localLogMode () const |
gives the local log-mode | |
void | localLogMode (LogMode m) |
sets the local log-mode | |
Effective | |
Level | effectiveLogLevel () const |
obtain the effective log-level for the Logger-object (i.e., resolve the dependencies on the global settings) | |
bool | effectiveStatisticMode () const |
returns true if the Logger-object is effectively in statistic-mode (as this might be depending on the global settings) | |
Static Public Member Functions | |
Static usage | |
static bool | is_slout (Level level=Level::Default) |
returns true if such an slout command will result in text being printed | |
static std::ostream & | slout (Level level=Level::Default) |
stream for logging-output (global) | |
static std::ostream & | ssout () |
stream for statistic-output (global) | |
static std::ostream & | sfout () |
stream for forced output (global) | |
Static internal library usage | |
static bool | is_ilout (Level level=Level::Default) |
stream for logging-output (global; used by internal libraries, e.g. Abacus) returns true if such an ilout command will result in text being printed | |
static std::ostream & | ilout (Level level=Level::Default) |
static std::ostream & | ifout () |
stream for forced output (global; used by internal libraries, e.g. Abacus) | |
Global | |
static Level | globalLogLevel () |
gives the global log-level | |
static void | globalLogLevel (Level level) |
sets the global log-level | |
static Level | globalInternalLibraryLogLevel () |
gives the internal-library log-level | |
static void | globalInternalLibraryLogLevel (Level level) |
sets the internal-library log-level | |
static Level | globalMinimumLogLevel () |
gives the globally minimally required log-level | |
static void | globalMinimumLogLevel (Level level) |
sets the globally minimally required log-level | |
static bool | globalStatisticMode () |
returns true if we are globally in statistic mode | |
static void | globalStatisticMode (bool s) |
sets whether we are globally in statistic mode | |
static void | setWorldStream (std::ostream &o) |
change the stream to which allowed output is written (by default: std::cout ) | |
Private Attributes | |
Level | m_loglevel |
LogMode | m_logmode |
Static Private Attributes | |
static Level | m_globallibraryloglevel |
static Level | m_globalloglevel |
static bool | m_globalstatisticmode |
static Level | m_minimumloglevel |
static std::ostream | nirvana |
static std::ostream * | world |
Centralized global and local logging facility working on streams like std::cout
.
The Logger class is a centralized logging environment with 2x2 different use-cases working together. All generated output is sent into the world-stream, i.e., std::cout
, if not set otherwise.
Logging vs. Statistic: The Logger differentiates between logging and statistic mode. When in logging mode, only the output written via the lout()/slout() commands is written to the world stream (according to loglevels). When in statistic mode, only the output of the sout()/ssout() commands is written. (Sidenote: there is also a forced output fout()/sfout() which is written independent on the current mode).
The idea of these two modi is that one can augment the code with output which is interesting in the normal computation mode via lout, but the same algorithm can also be run given tabular statistic-lines when e.g. batch-testing the algorithm on a set of benchmark instances.
Global vs. Local: You can choose to use the Logging facilities globally via the static outputs (slout(), ssout(), sfout()). Thereby the global log-level and statistic-mode settings are applied. Alternatively you can create your own Logging object with its own parameters only for your algorithm, and use the object methods lout(), sout(), and fout(). This allows you to turn output on for your own (new) algorithm, but keep the rest of the library silent.
Global Settings: The slout command takes an (optional) parameter given the importance of the output (aka. loglevel). The output is written only if the globalLogLevel is not higher. The method globalStatisticMode turn the statistic-mode on and off (thereby disabling or enabling the logging mode).
Furthermore, we have a globalMinimumLogLevel. This is used to globally forbid any output with too low importance written by any Logger-objects.
Local Settings: A Logger-object has its own set of settings, i.e., its own localLogLevel and an own localLogMode, which can be any of the enumerators in Logger::LogMode.
Typical Usage:
The simplest but restricted and verbose usage is to write
Logger::slout() << "1+2=" << (1+2) << std::endl;
The conceptually easiest and cleanest approach is to augment your algorithm class with a Logger. Multiple inheritance allows this pretty straightforwardly:
class MyAlgorithm : public MyBaseClass, protected Logger {
int myMethod();
}
MyAlgorithm::myMethod() {
lout() << "1+2=" << (1+2) << std::endl;
}
Internal Library Logging: Internal Libaries (as, e.g., Abacus) can use their own, global, set of logging functions. Its LogLevels are parallel and independent of the global LogLevel, but its logging is automatically turned off whenever the (global/static) Logger is in statistics-mode.
|
strong |
|
strong |
|
inline |
creates a new Logger-object with LogMode::Global and local log-level equal globalLogLevel
|
inlineexplicit |
|
inlineexplicit |
creates a new Logger-object with LogMode::Global and given local log-level
|
inline |
|
inline |
|
inline |
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
inline |
|
inlinestatic |
|
inline |
|
inline |
|
inline |
|
inlinestatic |
|
inlinestatic |
|
inline |
|
inlinestatic |