Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Logger.h
Go to the documentation of this file.
1 
32 #pragma once
33 
34 #include <ogdf/basic/basic.h>
35 
36 #include <algorithm>
37 #include <ostream>
38 #include <string>
39 
40 namespace ogdf {
41 
43 
102 class Logger {
103 public:
105  enum class Level { Minor, Medium, Default, High, Alarm, Force };
107  enum class LogMode {
109  Global,
111  GlobalLog,
113  Log,
115  Statistic
116  };
117 
118  class Indent {
120  int m_by;
121 
122  public:
123  explicit Indent(Logger* log, int by = 1) : m_log(log), m_by(by) { m_log->indent(m_by); }
124 
125  explicit Indent(Logger& log, int by = 1) : m_log(&log), m_by(by) { m_log->indent(m_by); }
126 
127  Indent(const Indent& copy) = delete;
128 
129  Indent& operator=(const Indent& other) = delete;
130 
132  };
133 
136 
138  explicit Logger(LogMode m) : Logger(m, m_globalloglevel) { }
139 
141  explicit Logger(Level level) : Logger(LogMode::Log, level) { }
142 
144  Logger(LogMode m, Level level) : m_loglevel(level), m_logmode(m), m_indent(0) { }
145 
148 
150  bool is_lout(Level level = Level::Default) const {
151  bool globalNotStatistic = !m_globalstatisticmode && m_logmode == LogMode::Global;
152  if (globalNotStatistic || m_logmode == LogMode::GlobalLog) {
153  return level >= m_globalloglevel;
154  } else {
155  return m_logmode == LogMode::Log && level >= std::max(m_loglevel, m_minimumloglevel);
156  }
157  }
158 
160  std::ostream& lout(Level level = Level::Default, bool indent = true) const {
161  if (is_lout(level)) {
162  if (indent && m_indent > 0) {
163  return *world << std::string(m_indent, '\t');
164  } else {
165  return *world;
166  }
167  } else {
168  return nirvana;
169  }
170  }
171 
173  std::ostream& sout() const {
176  ? *world
177  : nirvana;
178  }
179 
181  std::ostream& fout() const { return sfout(); }
182 
186 
188  static bool is_slout(Level level = Level::Default) {
189  return !m_globalstatisticmode && level >= m_globalloglevel;
190  }
191 
193  static std::ostream& slout(Level level = Level::Default) {
194  return is_slout(level) ? *world : nirvana;
195  }
196 
198  static std::ostream& ssout() { return m_globalstatisticmode ? *world : nirvana; }
199 
201  static std::ostream& sfout() { return *world; }
202 
206 
209  static bool is_ilout(Level level = Level::Default) {
211  }
212 
213  static std::ostream& ilout(Level level = Level::Default) {
214  return is_ilout(level) ? *world : nirvana;
215  }
216 
218  static std::ostream& ifout() { return *world; }
219 
223 
225  Level localLogLevel() const { return m_loglevel; }
226 
228  void localLogLevel(Level level) { m_loglevel = level; }
229 
231  LogMode localLogMode() const { return m_logmode; }
232 
234  void localLogMode(LogMode m) { m_logmode = m; }
235 
236  void indent(int by = 1) { setIndent(m_indent + by); }
237 
238  void dedent(int by = 1) { setIndent(m_indent - by); }
239 
240  int getIndent() const { return m_indent; }
241 
242  void setIndent(int indent) { m_indent = std::max(0, indent); }
243 
247 
249  static Level globalLogLevel() { return m_globalloglevel; }
250 
252  static void globalLogLevel(Level level) {
253  m_globalloglevel = level;
256  }
257  }
258 
261 
264 
267 
269  static void globalMinimumLogLevel(Level level) {
270  m_minimumloglevel = level;
273  }
274  }
275 
277  static bool globalStatisticMode() { return m_globalstatisticmode; }
278 
280  static void globalStatisticMode(bool s) { m_globalstatisticmode = s; }
281 
283  static void setWorldStream(std::ostream& o) { world = &o; }
284 
288 
292  return m_globalloglevel;
293  } else {
295  }
296  }
297 
299  bool effectiveStatisticMode() const {
300  return m_logmode == LogMode::Statistic
302  }
303 
305 
306 private:
307  static OGDF_EXPORT std::ostream nirvana;
308  static OGDF_EXPORT std::ostream* world;
309 
314 
317  int m_indent;
318 };
319 
320 inline std::ostream& operator<<(std::ostream& os, Logger::Level level) {
321  switch (level) {
323  os << "Minor";
324  break;
326  os << "Medium";
327  break;
329  os << "Default";
330  break;
331  case Logger::Level::High:
332  os << "High";
333  break;
335  os << "Alarm";
336  break;
338  os << "Force";
339  break;
340  }
341  return os;
342 }
343 
344 }
ogdf
The namespace for all OGDF objects.
Definition: multilevelmixer.cpp:39
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:290
ogdf::Logger::m_globalstatisticmode
static bool m_globalstatisticmode
Definition: Logger.h:313
ogdf::Logger::globalMinimumLogLevel
static Level globalMinimumLogLevel()
gives the globally minimally required log-level
Definition: Logger.h:266
ogdf::Logger::Indent::m_log
Logger * m_log
Definition: Logger.h:119
ogdf::AlgorithmFailureCode::Global
@ Global
ogdf::Logger::Level::Force
@ Force
ogdf::Logger::fout
std::ostream & fout() const
stream for forced output (local)
Definition: Logger.h:181
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:144
ogdf::Logger::globalInternalLibraryLogLevel
static void globalInternalLibraryLogLevel(Level level)
sets the internal-library log-level
Definition: Logger.h:263
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:150
ogdf::Logger::Logger
Logger()
creates a new Logger-object with LogMode::Global and local log-level equal globalLogLevel
Definition: Logger.h:135
ogdf::Logger::localLogMode
void localLogMode(LogMode m)
sets the local log-mode
Definition: Logger.h:234
ogdf::Logger::globalStatisticMode
static void globalStatisticMode(bool s)
sets whether we are globally in statistic mode
Definition: Logger.h:280
ogdf::Logger::Logger
Logger(Level level)
creates a new Logger-object with LogMode::Log and given local log-level
Definition: Logger.h:141
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:315
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:209
ogdf::Logger::Level
Level
supported log-levels from lowest to highest importance
Definition: Logger.h:105
ogdf::Logger::localLogLevel
void localLogLevel(Level level)
sets the local log-level
Definition: Logger.h:228
ogdf::Logger::ilout
static std::ostream & ilout(Level level=Level::Default)
Definition: Logger.h:213
ogdf::Logger::Level::Default
@ Default
ogdf::Logger::Indent::Indent
Indent(Logger &log, int by=1)
Definition: Logger.h:125
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:299
ogdf::Logger::globalInternalLibraryLogLevel
static Level globalInternalLibraryLogLevel()
gives the internal-library log-level
Definition: Logger.h:260
ogdf::Logger::m_indent
int m_indent
Definition: Logger.h:317
ogdf::Logger::ssout
static std::ostream & ssout()
stream for statistic-output (global)
Definition: Logger.h:198
ogdf::Logger::LogMode::Log
@ Log
the object is in logging mode, using its own localLogLevel
Minisat::Internal::copy
static void copy(const T &from, T &to)
Definition: Alg.h:61
ogdf::Logger::localLogLevel
Level localLogLevel() const
gives the local log-level
Definition: Logger.h:225
ogdf::Logger::globalLogLevel
static void globalLogLevel(Level level)
sets the global log-level
Definition: Logger.h:252
ogdf::Logger::m_minimumloglevel
static Level m_minimumloglevel
Definition: Logger.h:312
ogdf::Logger::localLogMode
LogMode localLogMode() const
gives the local log-mode
Definition: Logger.h:231
ogdf::Logger::indent
void indent(int by=1)
Definition: Logger.h:236
ogdf::MeasureEnum::log
@ log
ogdf::operator<<
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition: Array.h:983
ogdf::Logger::Logger
Logger(LogMode m)
creates a new Logger-object with given log-mode and local log-level equal globalLogLevel
Definition: Logger.h:138
ogdf::Logger::Indent::m_by
int m_by
Definition: Logger.h:120
ogdf::Logger::m_logmode
LogMode m_logmode
Definition: Logger.h:316
ogdf::Logger::globalStatisticMode
static bool globalStatisticMode()
returns true if we are globally in statistic mode
Definition: Logger.h:277
ogdf::Logger::Level::High
@ High
ogdf::Logger::world
static std::ostream * world
Definition: Logger.h:308
ogdf::Logger::globalLogLevel
static Level globalLogLevel()
gives the global log-level
Definition: Logger.h:249
ogdf::Logger::Indent::Indent
Indent(Logger *log, int by=1)
Definition: Logger.h:123
ogdf::Logger::sfout
static std::ostream & sfout()
stream for forced output (global)
Definition: Logger.h:201
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:188
ogdf::Logger::sout
std::ostream & sout() const
stream for statistic-output (local)
Definition: Logger.h:173
ogdf::Logger::ifout
static std::ostream & ifout()
stream for forced output (global; used by internal libraries, e.g. Abacus)
Definition: Logger.h:218
ogdf::Logger::LogMode::Global
@ Global
the object is in the same mode as the static Logger-class (i.e., global settings)
ogdf::Logger::setIndent
void setIndent(int indent)
Definition: Logger.h:242
ogdf::Logger::nirvana
static std::ostream nirvana
Definition: Logger.h:307
ogdf::Logger::m_globalloglevel
static Level m_globalloglevel
Definition: Logger.h:310
basic.h
Basic declarations, included by all source files.
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
ogdf::Logger::Indent::~Indent
~Indent()
Definition: Logger.h:131
ogdf::Logger::m_globallibraryloglevel
static Level m_globallibraryloglevel
Definition: Logger.h:311
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:283
ogdf::Logger::LogMode::Statistic
@ Statistic
the object is in statistic mode
ogdf::Logger::dedent
void dedent(int by=1)
Definition: Logger.h:238
ogdf::Logger
Centralized global and local logging facility working on streams like std::cout.
Definition: Logger.h:102
ogdf::Logger::globalMinimumLogLevel
static void globalMinimumLogLevel(Level level)
sets the globally minimally required log-level
Definition: Logger.h:269
ogdf::Logger::Level::Alarm
@ Alarm
ogdf::Logger::Indent::operator=
Indent & operator=(const Indent &other)=delete
ogdf::Logger::getIndent
int getIndent() const
Definition: Logger.h:240
ogdf::Logger::slout
static std::ostream & slout(Level level=Level::Default)
stream for logging-output (global)
Definition: Logger.h:193
ogdf::Logger::Indent
Definition: Logger.h:118
ogdf::Logger::lout
std::ostream & lout(Level level=Level::Default, bool indent=true) const
stream for logging-output (local)
Definition: Logger.h:160
ogdf::Logger::LogMode
LogMode
Local log-modes.
Definition: Logger.h:107