Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
ogdf::Logger Class Reference

Centralized global and local logging facility working on streams like std::cout. More...

#include <ogdf/basic/Logger.h>

+ Inheritance diagram for ogdf::Logger:

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
 

Detailed Description

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.

Definition at line 100 of file Logger.h.

Member Enumeration Documentation

◆ Level

supported log-levels from lowest to highest importance

Enumerator
Minor 
Medium 
Default 
High 
Alarm 
Force 

Definition at line 103 of file Logger.h.

◆ LogMode

Local log-modes.

Enumerator
Global 

the object is in the same mode as the static Logger-class (i.e., global settings)

GlobalLog 

the object is in logging mode, but uses the globalLogLevel

Log 

the object is in logging mode, using its own localLogLevel

Statistic 

the object is in statistic mode

Definition at line 105 of file Logger.h.

Constructor & Destructor Documentation

◆ Logger() [1/4]

ogdf::Logger::Logger ( )
inline

creates a new Logger-object with LogMode::Global and local log-level equal globalLogLevel

Definition at line 117 of file Logger.h.

◆ Logger() [2/4]

ogdf::Logger::Logger ( LogMode  m)
inlineexplicit

creates a new Logger-object with given log-mode and local log-level equal globalLogLevel

Definition at line 120 of file Logger.h.

◆ Logger() [3/4]

ogdf::Logger::Logger ( Level  level)
inlineexplicit

creates a new Logger-object with LogMode::Global and given local log-level

Definition at line 123 of file Logger.h.

◆ Logger() [4/4]

ogdf::Logger::Logger ( LogMode  m,
Level  level 
)
inline

creates a new Logger-object with given log-mode and given local log-level

Definition at line 126 of file Logger.h.

Member Function Documentation

◆ effectiveLogLevel()

Level ogdf::Logger::effectiveLogLevel ( ) const
inline

obtain the effective log-level for the Logger-object (i.e., resolve the dependencies on the global settings)

Definition at line 256 of file Logger.h.

◆ effectiveStatisticMode()

bool ogdf::Logger::effectiveStatisticMode ( ) const
inline

returns true if the Logger-object is effectively in statistic-mode (as this might be depending on the global settings)

Definition at line 265 of file Logger.h.

◆ fout()

std::ostream & ogdf::Logger::fout ( ) const
inline

stream for forced output (local)

Definition at line 155 of file Logger.h.

◆ globalInternalLibraryLogLevel() [1/2]

static Level ogdf::Logger::globalInternalLibraryLogLevel ( )
inlinestatic

gives the internal-library log-level

Definition at line 226 of file Logger.h.

◆ globalInternalLibraryLogLevel() [2/2]

static void ogdf::Logger::globalInternalLibraryLogLevel ( Level  level)
inlinestatic

sets the internal-library log-level

Definition at line 229 of file Logger.h.

◆ globalLogLevel() [1/2]

static Level ogdf::Logger::globalLogLevel ( )
inlinestatic

gives the global log-level

Definition at line 215 of file Logger.h.

◆ globalLogLevel() [2/2]

static void ogdf::Logger::globalLogLevel ( Level  level)
inlinestatic

sets the global log-level

Definition at line 218 of file Logger.h.

◆ globalMinimumLogLevel() [1/2]

static Level ogdf::Logger::globalMinimumLogLevel ( )
inlinestatic

gives the globally minimally required log-level

Definition at line 232 of file Logger.h.

◆ globalMinimumLogLevel() [2/2]

static void ogdf::Logger::globalMinimumLogLevel ( Level  level)
inlinestatic

sets the globally minimally required log-level

Definition at line 235 of file Logger.h.

◆ globalStatisticMode() [1/2]

static bool ogdf::Logger::globalStatisticMode ( )
inlinestatic

returns true if we are globally in statistic mode

Definition at line 243 of file Logger.h.

◆ globalStatisticMode() [2/2]

static void ogdf::Logger::globalStatisticMode ( bool  s)
inlinestatic

sets whether we are globally in statistic mode

Definition at line 246 of file Logger.h.

◆ ifout()

static std::ostream & ogdf::Logger::ifout ( )
inlinestatic

stream for forced output (global; used by internal libraries, e.g. Abacus)

Definition at line 192 of file Logger.h.

◆ ilout()

static std::ostream & ogdf::Logger::ilout ( Level  level = Level::Default)
inlinestatic

Definition at line 187 of file Logger.h.

◆ is_ilout()

static bool ogdf::Logger::is_ilout ( Level  level = Level::Default)
inlinestatic

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

Definition at line 183 of file Logger.h.

◆ is_lout()

bool ogdf::Logger::is_lout ( Level  level = Level::Default) const
inline

returns true if such an lout command will result in text being printed

Definition at line 132 of file Logger.h.

◆ is_slout()

static bool ogdf::Logger::is_slout ( Level  level = Level::Default)
inlinestatic

returns true if such an slout command will result in text being printed

Definition at line 162 of file Logger.h.

◆ localLogLevel() [1/2]

Level ogdf::Logger::localLogLevel ( ) const
inline

gives the local log-level

Definition at line 199 of file Logger.h.

◆ localLogLevel() [2/2]

void ogdf::Logger::localLogLevel ( Level  level)
inline

sets the local log-level

Definition at line 202 of file Logger.h.

◆ localLogMode() [1/2]

LogMode ogdf::Logger::localLogMode ( ) const
inline

gives the local log-mode

Definition at line 205 of file Logger.h.

◆ localLogMode() [2/2]

void ogdf::Logger::localLogMode ( LogMode  m)
inline

sets the local log-mode

Definition at line 208 of file Logger.h.

◆ lout()

std::ostream & ogdf::Logger::lout ( Level  level = Level::Default) const
inline

stream for logging-output (local)

Definition at line 142 of file Logger.h.

◆ setWorldStream()

static void ogdf::Logger::setWorldStream ( std::ostream &  o)
inlinestatic

change the stream to which allowed output is written (by default: std::cout)

Definition at line 249 of file Logger.h.

◆ sfout()

static std::ostream & ogdf::Logger::sfout ( )
inlinestatic

stream for forced output (global)

Definition at line 175 of file Logger.h.

◆ slout()

static std::ostream & ogdf::Logger::slout ( Level  level = Level::Default)
inlinestatic

stream for logging-output (global)

Definition at line 167 of file Logger.h.

◆ sout()

std::ostream & ogdf::Logger::sout ( ) const
inline

stream for statistic-output (local)

Definition at line 147 of file Logger.h.

◆ ssout()

static std::ostream & ogdf::Logger::ssout ( )
inlinestatic

stream for statistic-output (global)

Definition at line 172 of file Logger.h.

Member Data Documentation

◆ m_globallibraryloglevel

Level ogdf::Logger::m_globallibraryloglevel
staticprivate

Definition at line 277 of file Logger.h.

◆ m_globalloglevel

Level ogdf::Logger::m_globalloglevel
staticprivate

Definition at line 276 of file Logger.h.

◆ m_globalstatisticmode

bool ogdf::Logger::m_globalstatisticmode
staticprivate

Definition at line 279 of file Logger.h.

◆ m_loglevel

Level ogdf::Logger::m_loglevel
private

Definition at line 281 of file Logger.h.

◆ m_logmode

LogMode ogdf::Logger::m_logmode
private

Definition at line 282 of file Logger.h.

◆ m_minimumloglevel

Level ogdf::Logger::m_minimumloglevel
staticprivate

Definition at line 278 of file Logger.h.

◆ nirvana

std::ostream ogdf::Logger::nirvana
staticprivate

Definition at line 273 of file Logger.h.

◆ world

std::ostream* ogdf::Logger::world
staticprivate

Definition at line 274 of file Logger.h.


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