Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Logger.h
Go to the documentation of this file.
1 
32 #pragma once
33 
35 
36 #include <algorithm>
37 
38 namespace ogdf {
39 
41 
100 class Logger {
101 public:
103  enum class Level { Minor, Medium, Default, High, Alarm, Force };
105  enum class LogMode {
107  Global,
109  GlobalLog,
111  Log,
113  Statistic
114  };
115 
116  class Indent {
118  int m_by;
119 
120  public:
121  explicit Indent(Logger* log, int by = 1) : m_log(log), m_by(by) { m_log->indent(m_by); }
122 
123  explicit Indent(Logger& log, int by = 1) : m_log(&log), m_by(by) { m_log->indent(m_by); }
124 
125  Indent(const Indent& copy) = delete;
126 
127  Indent& operator=(const Indent& other) = delete;
128 
130  };
131 
134 
136  explicit Logger(LogMode m) : Logger(m, m_globalloglevel) { }
137 
139  explicit Logger(Level level) : Logger(LogMode::Log, level) { }
140 
142  Logger(LogMode m, Level level) : m_loglevel(level), m_logmode(m), m_indent(0) { }
143 
146 
148  bool is_lout(Level level = Level::Default) const {
149  bool globalNotStatistic = !m_globalstatisticmode && m_logmode == LogMode::Global;
150  if (globalNotStatistic || m_logmode == LogMode::GlobalLog) {
151  return level >= m_globalloglevel;
152  } else {
153  return m_logmode == LogMode::Log && level >= std::max(m_loglevel, m_minimumloglevel);
154  }
155  }
156 
158  std::ostream& lout(Level level = Level::Default, bool indent = true) const {
159  if (is_lout(level)) {
160  if (indent && m_indent > 0) {
161  return *world << std::string(m_indent, '\t');
162  } else {
163  return *world;
164  }
165  } else {
166  return nirvana;
167  }
168  }
169 
171  std::ostream& sout() const {
174  ? *world
175  : nirvana;
176  }
177 
179  std::ostream& fout() const { return sfout(); }
180 
184 
186  static bool is_slout(Level level = Level::Default) {
187  return !m_globalstatisticmode && level >= m_globalloglevel;
188  }
189 
191  static std::ostream& slout(Level level = Level::Default) {
192  return is_slout(level) ? *world : nirvana;
193  }
194 
196  static std::ostream& ssout() { return m_globalstatisticmode ? *world : nirvana; }
197 
199  static std::ostream& sfout() { return *world; }
200 
204 
207  static bool is_ilout(Level level = Level::Default) {
209  }
210 
211  static std::ostream& ilout(Level level = Level::Default) {
212  return is_ilout(level) ? *world : nirvana;
213  }
214 
216  static std::ostream& ifout() { return *world; }
217 
221 
223  Level localLogLevel() const { return m_loglevel; }
224 
226  void localLogLevel(Level level) { m_loglevel = level; }
227 
229  LogMode localLogMode() const { return m_logmode; }
230 
232  void localLogMode(LogMode m) { m_logmode = m; }
233 
234  void indent(int by = 1) { setIndent(m_indent + by); }
235 
236  void dedent(int by = 1) { setIndent(m_indent - by); }
237 
238  int getIndent() const { return m_indent; }
239 
240  void setIndent(int indent) { m_indent = std::max(0, indent); }
241 
245 
247  static Level globalLogLevel() { return m_globalloglevel; }
248 
250  static void globalLogLevel(Level level) {
251  m_globalloglevel = level;
254  }
255  }
256 
259 
262 
265 
267  static void globalMinimumLogLevel(Level level) {
268  m_minimumloglevel = level;
271  }
272  }
273 
275  static bool globalStatisticMode() { return m_globalstatisticmode; }
276 
278  static void globalStatisticMode(bool s) { m_globalstatisticmode = s; }
279 
281  static void setWorldStream(std::ostream& o) { world = &o; }
282 
286 
290  return m_globalloglevel;
291  } else {
293  }
294  }
295 
297  bool effectiveStatisticMode() const {
298  return m_logmode == LogMode::Statistic
300  }
301 
303 
304 private:
305  static OGDF_EXPORT std::ostream nirvana;
306  static OGDF_EXPORT std::ostream* world;
307 
312 
315  int m_indent;
316 };
317 
318 inline std::ostream& operator<<(std::ostream& os, Logger::Level level) {
319  switch (level) {
321  os << "Minor";
322  break;
324  os << "Medium";
325  break;
327  os << "Default";
328  break;
329  case Logger::Level::High:
330  os << "High";
331  break;
333  os << "Alarm";
334  break;
336  os << "Force";
337  break;
338  }
339  return os;
340 }
341 
342 }
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:288
ogdf::Logger::m_globalstatisticmode
static bool m_globalstatisticmode
Definition: Logger.h:311
ogdf::Logger::globalMinimumLogLevel
static Level globalMinimumLogLevel()
gives the globally minimally required log-level
Definition: Logger.h:264
ogdf::Logger::Indent::m_log
Logger * m_log
Definition: Logger.h:117
ogdf::AlgorithmFailureCode::Global
@ Global
ogdf::Logger::Level::Force
@ Force
ogdf::Logger::fout
std::ostream & fout() const
stream for forced output (local)
Definition: Logger.h:179
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:142
ogdf::Logger::globalInternalLibraryLogLevel
static void globalInternalLibraryLogLevel(Level level)
sets the internal-library log-level
Definition: Logger.h:261
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:148
ogdf::Logger::Logger
Logger()
creates a new Logger-object with LogMode::Global and local log-level equal globalLogLevel
Definition: Logger.h:133
ogdf::Logger::localLogMode
void localLogMode(LogMode m)
sets the local log-mode
Definition: Logger.h:232
ogdf::Logger::globalStatisticMode
static void globalStatisticMode(bool s)
sets whether we are globally in statistic mode
Definition: Logger.h:278
ogdf::Logger::Logger
Logger(Level level)
creates a new Logger-object with LogMode::Log and given local log-level
Definition: Logger.h:139
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:313
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:207
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:226
ogdf::Logger::ilout
static std::ostream & ilout(Level level=Level::Default)
Definition: Logger.h:211
ogdf::Logger::Level::Default
@ Default
ogdf::Logger::Indent::Indent
Indent(Logger &log, int by=1)
Definition: Logger.h:123
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:297
ogdf::Logger::globalInternalLibraryLogLevel
static Level globalInternalLibraryLogLevel()
gives the internal-library log-level
Definition: Logger.h:258
ogdf::Logger::m_indent
int m_indent
Definition: Logger.h:315
ogdf::Logger::ssout
static std::ostream & ssout()
stream for statistic-output (global)
Definition: Logger.h:196
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:223
ogdf::Logger::globalLogLevel
static void globalLogLevel(Level level)
sets the global log-level
Definition: Logger.h:250
ogdf::Logger::m_minimumloglevel
static Level m_minimumloglevel
Definition: Logger.h:310
ogdf::Logger::localLogMode
LogMode localLogMode() const
gives the local log-mode
Definition: Logger.h:229
ogdf::Logger::indent
void indent(int by=1)
Definition: Logger.h:234
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:978
ogdf::Logger::Logger
Logger(LogMode m)
creates a new Logger-object with given log-mode and local log-level equal globalLogLevel
Definition: Logger.h:136
ogdf::Logger::Indent::m_by
int m_by
Definition: Logger.h:118
ogdf::Logger::m_logmode
LogMode m_logmode
Definition: Logger.h:314
ogdf::Logger::globalStatisticMode
static bool globalStatisticMode()
returns true if we are globally in statistic mode
Definition: Logger.h:275
ogdf::Logger::Level::High
@ High
ogdf::Logger::world
static std::ostream * world
Definition: Logger.h:306
ogdf::Logger::globalLogLevel
static Level globalLogLevel()
gives the global log-level
Definition: Logger.h:247
ogdf::Logger::Indent::Indent
Indent(Logger *log, int by=1)
Definition: Logger.h:121
ogdf::Logger::sfout
static std::ostream & sfout()
stream for forced output (global)
Definition: Logger.h:199
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:186
ogdf::Logger::sout
std::ostream & sout() const
stream for statistic-output (local)
Definition: Logger.h:171
ogdf::Logger::ifout
static std::ostream & ifout()
stream for forced output (global; used by internal libraries, e.g. Abacus)
Definition: Logger.h:216
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:240
ogdf::Logger::nirvana
static std::ostream nirvana
Definition: Logger.h:305
ogdf::Logger::m_globalloglevel
static Level m_globalloglevel
Definition: Logger.h:308
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:129
config.h
Basic configuration file.
ogdf::Logger::m_globallibraryloglevel
static Level m_globallibraryloglevel
Definition: Logger.h:309
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:281
ogdf::Logger::LogMode::Statistic
@ Statistic
the object is in statistic mode
ogdf::Logger::dedent
void dedent(int by=1)
Definition: Logger.h:236
ogdf::Logger
Centralized global and local logging facility working on streams like std::cout.
Definition: Logger.h:100
ogdf::Logger::globalMinimumLogLevel
static void globalMinimumLogLevel(Level level)
sets the globally minimally required log-level
Definition: Logger.h:267
ogdf::Logger::Level::Alarm
@ Alarm
ogdf::Logger::Indent::operator=
Indent & operator=(const Indent &other)=delete
ogdf::Logger::getIndent
int getIndent() const
Definition: Logger.h:238
ogdf::Logger::slout
static std::ostream & slout(Level level=Level::Default)
stream for logging-output (global)
Definition: Logger.h:191
ogdf::Logger::Indent
Definition: Logger.h:116
ogdf::Logger::lout
std::ostream & lout(Level level=Level::Default, bool indent=true) const
stream for logging-output (local)
Definition: Logger.h:158
ogdf::Logger::LogMode
LogMode
Local log-modes.
Definition: Logger.h:105