Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

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:

Classes

class  Indent
 

Public Types

enum  Level { Level::Minor, Level::Medium, Level::Default, Level::High, Level::Alarm, Level::Force }
 supported log-levels from lowest to highest importance More...
 
enum  LogMode { LogMode::Global, LogMode::GlobalLog, LogMode::Log, LogMode::Statistic }
 Local log-modes. More...
 

Public Member Functions

 Logger ()
 creates a new Logger-object with LogMode::Global and local log-level equal globalLogLevel More...
 
 Logger (Level level)
 creates a new Logger-object with LogMode::Log and given local log-level More...
 
 Logger (LogMode m)
 creates a new Logger-object with given log-mode and local log-level equal globalLogLevel More...
 
 Logger (LogMode m, Level level)
 creates a new Logger-object with given log-mode and given local log-level More...
 
Usage
bool is_lout (Level level=Level::Default) const
 returns true if such an lout command will result in text being printed More...
 
std::ostream & lout (Level level=Level::Default, bool indent=true) const
 stream for logging-output (local) More...
 
std::ostream & sout () const
 stream for statistic-output (local) More...
 
std::ostream & fout () const
 stream for forced output (local) More...
 
Local
Level localLogLevel () const
 gives the local log-level More...
 
void localLogLevel (Level level)
 sets the local log-level More...
 
LogMode localLogMode () const
 gives the local log-mode More...
 
void localLogMode (LogMode m)
 sets the local log-mode More...
 
void indent (int by=1)
 
void dedent (int by=1)
 
int getIndent () const
 
void setIndent (int indent)
 
Effective
Level effectiveLogLevel () const
 obtain the effective log-level for the Logger-object (i.e., resolve the dependencies on the global settings) More...
 
bool effectiveStatisticMode () const
 returns true if the Logger-object is effectively in statistic-mode (as this might be depending on the global settings) More...
 

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 More...
 
static std::ostream & slout (Level level=Level::Default)
 stream for logging-output (global) More...
 
static std::ostream & ssout ()
 stream for statistic-output (global) More...
 
static std::ostream & sfout ()
 stream for forced output (global) More...
 
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 More...
 
static std::ostream & ilout (Level level=Level::Default)
 
static std::ostream & ifout ()
 stream for forced output (global; used by internal libraries, e.g. Abacus) More...
 
Global
static Level globalLogLevel ()
 gives the global log-level More...
 
static void globalLogLevel (Level level)
 sets the global log-level More...
 
static Level globalInternalLibraryLogLevel ()
 gives the internal-library log-level More...
 
static void globalInternalLibraryLogLevel (Level level)
 sets the internal-library log-level More...
 
static Level globalMinimumLogLevel ()
 gives the globally minimally required log-level More...
 
static void globalMinimumLogLevel (Level level)
 sets the globally minimally required log-level More...
 
static bool globalStatisticMode ()
 returns true if we are globally in statistic mode More...
 
static void globalStatisticMode (bool s)
 sets whether we are globally in statistic mode More...
 
static void setWorldStream (std::ostream &o)
 change the stream to which allowed output is written (by default: std::cout) More...
 

Private Attributes

int m_indent
 
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 102 of file Logger.h.

Member Enumeration Documentation

◆ Level

enum ogdf::Logger::Level
strong

supported log-levels from lowest to highest importance

Enumerator
Minor 
Medium 
Default 
High 
Alarm 
Force 

Definition at line 105 of file Logger.h.

◆ LogMode

enum ogdf::Logger::LogMode
strong

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 107 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 135 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 138 of file Logger.h.

◆ Logger() [3/4]

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

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

Definition at line 141 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 144 of file Logger.h.

Member Function Documentation

◆ dedent()

void ogdf::Logger::dedent ( int  by = 1)
inline

Definition at line 238 of file Logger.h.

◆ 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 290 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 299 of file Logger.h.

◆ fout()

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

stream for forced output (local)

Definition at line 181 of file Logger.h.

◆ getIndent()

int ogdf::Logger::getIndent ( ) const
inline

Definition at line 240 of file Logger.h.

◆ globalInternalLibraryLogLevel() [1/2]

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

gives the internal-library log-level

Definition at line 260 of file Logger.h.

◆ globalInternalLibraryLogLevel() [2/2]

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

sets the internal-library log-level

Definition at line 263 of file Logger.h.

◆ globalLogLevel() [1/2]

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

gives the global log-level

Definition at line 249 of file Logger.h.

◆ globalLogLevel() [2/2]

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

sets the global log-level

Definition at line 252 of file Logger.h.

◆ globalMinimumLogLevel() [1/2]

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

gives the globally minimally required log-level

Definition at line 266 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 269 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 277 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 280 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 218 of file Logger.h.

◆ ilout()

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

Definition at line 213 of file Logger.h.

◆ indent()

void ogdf::Logger::indent ( int  by = 1)
inline

Definition at line 236 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 209 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 150 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 188 of file Logger.h.

◆ localLogLevel() [1/2]

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

gives the local log-level

Definition at line 225 of file Logger.h.

◆ localLogLevel() [2/2]

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

sets the local log-level

Definition at line 228 of file Logger.h.

◆ localLogMode() [1/2]

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

gives the local log-mode

Definition at line 231 of file Logger.h.

◆ localLogMode() [2/2]

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

sets the local log-mode

Definition at line 234 of file Logger.h.

◆ lout()

std::ostream& ogdf::Logger::lout ( Level  level = Level::Default,
bool  indent = true 
) const
inline

stream for logging-output (local)

Definition at line 160 of file Logger.h.

◆ setIndent()

void ogdf::Logger::setIndent ( int  indent)
inline

Definition at line 242 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 283 of file Logger.h.

◆ sfout()

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

stream for forced output (global)

Definition at line 201 of file Logger.h.

◆ slout()

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

stream for logging-output (global)

Definition at line 193 of file Logger.h.

◆ sout()

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

stream for statistic-output (local)

Definition at line 173 of file Logger.h.

◆ ssout()

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

stream for statistic-output (global)

Definition at line 198 of file Logger.h.

Member Data Documentation

◆ m_globallibraryloglevel

Level ogdf::Logger::m_globallibraryloglevel
staticprivate

Definition at line 311 of file Logger.h.

◆ m_globalloglevel

Level ogdf::Logger::m_globalloglevel
staticprivate

Definition at line 310 of file Logger.h.

◆ m_globalstatisticmode

bool ogdf::Logger::m_globalstatisticmode
staticprivate

Definition at line 313 of file Logger.h.

◆ m_indent

int ogdf::Logger::m_indent
private

Definition at line 317 of file Logger.h.

◆ m_loglevel

Level ogdf::Logger::m_loglevel
private

Definition at line 315 of file Logger.h.

◆ m_logmode

LogMode ogdf::Logger::m_logmode
private

Definition at line 316 of file Logger.h.

◆ m_minimumloglevel

Level ogdf::Logger::m_minimumloglevel
staticprivate

Definition at line 312 of file Logger.h.

◆ nirvana

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

Definition at line 307 of file Logger.h.

◆ world

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

Definition at line 308 of file Logger.h.


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