Open
Graph Drawing
Framework

 v. 2022.02 (Dogwood)
 

Logger.h
Go to the documentation of this file.
1 
32 #pragma once
33 
35 #include <algorithm>
36 
37 namespace ogdf {
38 
40 
99 class Logger {
100 
101 public:
103  enum class Level {
104  Minor,
105  Medium,
106  Default,
107  High,
108  Alarm,
109  Force
110  };
112  enum class LogMode {
114  Global,
116  GlobalLog,
118  Log,
120  Statistic
121  };
122 
126  explicit Logger(LogMode m) : Logger(m, m_globalloglevel) {}
128  explicit Logger(Level level) : Logger(LogMode::Global, level) {}
130  Logger(LogMode m, Level level) :
131  m_loglevel(level), m_logmode(m) {}
132 
135 
137  bool is_lout(Level level = Level::Default) const {
138  bool globalNotStatistic = !m_globalstatisticmode && m_logmode == LogMode::Global;
139  if (globalNotStatistic || m_logmode==LogMode::GlobalLog) {
140  return level >= m_globalloglevel;
141  } else {
142  return m_logmode==LogMode::Log
143  && level >= std::max(m_loglevel, m_minimumloglevel);
144  }
145  }
147  std::ostream& lout(Level level = Level::Default) const {
148  return is_lout(level) ? *world : nirvana;
149  }
151  std::ostream& sout() const {
153  }
155  std::ostream& fout() const {
156  return sfout();
157  }
158 
162 
164  static bool is_slout(Level level = Level::Default) {
165  return !m_globalstatisticmode && level >= m_globalloglevel;
166  }
168  static std::ostream& slout(Level level = Level::Default) {
169  return is_slout(level) ? *world : nirvana;
170  }
172  static std::ostream& ssout() {
173  return m_globalstatisticmode ? *world : nirvana;
174  }
176  static std::ostream& sfout() {
177  return *world;
178  }
179 
183 
186  static bool is_ilout(Level level = Level::Default) {
188  }
189  static std::ostream& ilout(Level level = Level::Default) {
190  return is_ilout(level) ? *world : nirvana;
191  }
192 
194  static std::ostream& ifout() {
195  return *world;
196  }
197 
201 
204  return m_loglevel;
205  }
207  void localLogLevel(Level level) {
208  m_loglevel = level;
209  }
212  return m_logmode;
213  }
216  m_logmode = m;
217  }
218 
222 
224  static Level globalLogLevel() { return m_globalloglevel; }
226  static void globalLogLevel(Level level) {
227  m_globalloglevel = level;
230  }
231 
236 
240  static void globalMinimumLogLevel(Level level) {
241  m_minimumloglevel = level;
244  }
245 
247  static bool globalStatisticMode() { return m_globalstatisticmode; }
249  static void globalStatisticMode(bool s) { m_globalstatisticmode = s; }
250 
252  static void setWorldStream(std::ostream& o) { world = &o; }
253 
257 
261  return m_globalloglevel;
262  else
264  }
265 
267  bool effectiveStatisticMode() const {
269  }
270 
272 
273 private:
274  static OGDF_EXPORT std::ostream nirvana;
275  static OGDF_EXPORT std::ostream* world;
276 
281 
284 };
285 
286 inline std::ostream &operator<<(std::ostream &os, Logger::Level level) {
287  switch (level) {
289  os << "Minor";
290  break;
292  os << "Medium";
293  break;
295  os << "Default";
296  break;
297  case Logger::Level::High:
298  os << "High";
299  break;
301  os << "Alarm";
302  break;
304  os << "Force";
305  break;
306  }
307  return os;
308 }
309 
310 }
ogdf
The namespace for all OGDF objects.
Definition: AugmentationModule.h:36
ogdf::Logger::effectiveLogLevel
Level effectiveLogLevel() const
obtain the effective log-level for the Logger-object (i.e., resolve the dependencies on the global se...
Definition: Logger.h:259
ogdf::Logger::m_globalstatisticmode
static bool m_globalstatisticmode
Definition: Logger.h:280
ogdf::Logger::globalMinimumLogLevel
static Level globalMinimumLogLevel()
gives the globally minimally required log-level
Definition: Logger.h:238
ogdf::AlgorithmFailureCode::Global
@ Global
ogdf::Logger::Level::Force
@ Force
ogdf::Logger::fout
std::ostream & fout() const
stream for forced output (local)
Definition: Logger.h:155
ogdf::Logger::Level::Minor
@ Minor
ogdf::Logger::Logger
Logger(LogMode m, Level level)
creates a new Logger-object with given log-mode and given local log-level
Definition: Logger.h:130
ogdf::Logger::globalInternalLibraryLogLevel
static void globalInternalLibraryLogLevel(Level level)
sets the internal-library log-level
Definition: Logger.h:235
ogdf::Logger::is_lout
bool is_lout(Level level=Level::Default) const
returns true if such an lout command will result in text being printed
Definition: Logger.h:137
ogdf::Logger::Logger
Logger()
creates a new Logger-object with LogMode::Global and local log-level equal globalLogLevel
Definition: Logger.h:124
ogdf::Logger::localLogMode
void localLogMode(LogMode m)
sets the local log-mode
Definition: Logger.h:215
ogdf::Logger::globalStatisticMode
static void globalStatisticMode(bool s)
sets whether we are globally in statistic mode
Definition: Logger.h:249
ogdf::Logger::Logger
Logger(Level level)
creates a new Logger-object with LogMode::Global and given local log-level
Definition: Logger.h:128
ogdf::Logger::LogMode::GlobalLog
@ GlobalLog
the object is in logging mode, but uses the globalLogLevel
ogdf::Logger::m_loglevel
Level m_loglevel
Definition: Logger.h:282
ogdf::Logger::is_ilout
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 i...
Definition: Logger.h:186
ogdf::Logger::Level
Level
supported log-levels from lowest to highest importance
Definition: Logger.h:103
ogdf::Logger::localLogLevel
void localLogLevel(Level level)
sets the local log-level
Definition: Logger.h:207
ogdf::Logger::ilout
static std::ostream & ilout(Level level=Level::Default)
Definition: Logger.h:189
ogdf::Logger::Level::Default
@ Default
ogdf::Logger::Level::Medium
@ Medium
ogdf::Logger::effectiveStatisticMode
bool effectiveStatisticMode() const
returns true if the Logger-object is effectively in statistic-mode (as this might be depending on the...
Definition: Logger.h:267
ogdf::Logger::globalInternalLibraryLogLevel
static Level globalInternalLibraryLogLevel()
gives the internal-library log-level
Definition: Logger.h:233
ogdf::Logger::ssout
static std::ostream & ssout()
stream for statistic-output (global)
Definition: Logger.h:172
ogdf::Logger::LogMode::Log
@ Log
the object is in logging mode, using its own localLogLevel
ogdf::Logger::localLogLevel
Level localLogLevel() const
gives the local log-level
Definition: Logger.h:203
ogdf::Logger::globalLogLevel
static void globalLogLevel(Level level)
sets the global log-level
Definition: Logger.h:226
ogdf::Logger::m_minimumloglevel
static Level m_minimumloglevel
Definition: Logger.h:279
ogdf::Logger::localLogMode
LogMode localLogMode() const
gives the local log-mode
Definition: Logger.h:211
ogdf::operator<<
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition: Array.h:949
ogdf::Logger::Logger
Logger(LogMode m)
creates a new Logger-object with given log-mode and local log-level equal globalLogLevel
Definition: Logger.h:126
ogdf::Logger::m_logmode
LogMode m_logmode
Definition: Logger.h:283
ogdf::Logger::globalStatisticMode
static bool globalStatisticMode()
returns true if we are globally in statistic mode
Definition: Logger.h:247
ogdf::Logger::Level::High
@ High
ogdf::Logger::world
static std::ostream * world
Definition: Logger.h:275
ogdf::Logger::globalLogLevel
static Level globalLogLevel()
gives the global log-level
Definition: Logger.h:224
ogdf::Logger::sfout
static std::ostream & sfout()
stream for forced output (global)
Definition: Logger.h:176
ogdf::Logger::is_slout
static bool is_slout(Level level=Level::Default)
returns true if such an slout command will result in text being printed
Definition: Logger.h:164
ogdf::Logger::sout
std::ostream & sout() const
stream for statistic-output (local)
Definition: Logger.h:151
ogdf::Logger::ifout
static std::ostream & ifout()
stream for forced output (global; used by internal libraries, e.g. Abacus)
Definition: Logger.h:194
ogdf::Logger::LogMode::Global
@ Global
the object is in the same mode as the static Logger-class (i.e., global settings)
ogdf::Logger::nirvana
static std::ostream nirvana
Definition: Logger.h:274
ogdf::Logger::m_globalloglevel
static Level m_globalloglevel
Definition: Logger.h:277
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:99
ogdf::Logger::lout
std::ostream & lout(Level level=Level::Default) const
stream for logging-output (local)
Definition: Logger.h:147
config.h
Basic configuration file.
ogdf::Logger::m_globallibraryloglevel
static Level m_globallibraryloglevel
Definition: Logger.h:278
ogdf::Logger::setWorldStream
static void setWorldStream(std::ostream &o)
change the stream to which allowed output is written (by default: std::cout)
Definition: Logger.h:252
ogdf::Logger::LogMode::Statistic
@ Statistic
the object is in statistic mode
ogdf::Logger
Centralized global and local logging facility working on streams like std::cout.
Definition: Logger.h:99
ogdf::Logger::globalMinimumLogLevel
static void globalMinimumLogLevel(Level level)
sets the globally minimally required log-level
Definition: Logger.h:240
ogdf::Logger::Level::Alarm
@ Alarm
ogdf::Logger::slout
static std::ostream & slout(Level level=Level::Default)
stream for logging-output (global)
Definition: Logger.h:168
ogdf::Logger::LogMode
LogMode
Local log-modes.
Definition: Logger.h:112