Open
Graph Drawing
Framework

 v. snapshot-2017-02-16
 

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 l) : Logger(LogMode::Global, l) {}
131  m_loglevel(l), 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 l = Level::Default) const {
148  return (is_lout(l)) ? *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 l = Level::Default) {
165  return !m_globalstatisticmode && l >= m_globalloglevel;
166  }
168  static std::ostream& slout(Level l = Level::Default) {
169  return is_slout(l) ? *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 l = Level::Default) {
188  }
189  static std::ostream& ilout(Level l = Level::Default) {
190  return is_ilout(l) ? *world : nirvana;
191  }
192 
194  static std::ostream& ifout() {
195  return *world;
196  }
197 
201 
204  return m_loglevel;
205  }
208  m_loglevel = l;
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 l) {
227  m_globalloglevel = l;
230  }
231 
236 
240  static void globalMinimumLogLevel(Level l) {
241  m_minimumloglevel = l;
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 ostream &operator<<(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 }
Logger(LogMode m)
creates a new Logger-object with given log-mode and local log-level equal globalLogLevel ...
Definition: Logger.h:126
static std::ostream * world
Definition: Logger.h:275
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:99
void localLogLevel(Level l)
sets the local log-level
Definition: Logger.h:207
the object is in logging mode, but uses the globalLogLevel
Basic configuration file.
static bool globalStatisticMode()
returns true if we are globally in statistic mode
Definition: Logger.h:247
LogMode m_logmode
Definition: Logger.h:283
LogMode
Local log-modes.
Definition: Logger.h:112
static bool m_globalstatisticmode
Definition: Logger.h:280
static std::ostream & sfout()
stream for forced output (global)
Definition: Logger.h:176
ostream & operator<<(ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition: Array.h:764
Level localLogLevel() const
gives the local log-level
Definition: Logger.h:203
std::ostream & lout(Level l=Level::Default) const
stream for logging-output (local)
Definition: Logger.h:147
std::ostream & sout() const
stream for statistic-output (local)
Definition: Logger.h:151
static void globalLogLevel(Level l)
sets the global log-level
Definition: Logger.h:226
std::ostream & fout() const
stream for forced output (local)
Definition: Logger.h:155
static Level m_globalloglevel
Definition: Logger.h:277
static std::ostream & ifout()
stream for forced output (global; used by internal libraries, e.g. Abacus)
Definition: Logger.h:194
static bool is_slout(Level l=Level::Default)
returns true if such an slout command will result in text being printed
Definition: Logger.h:164
Logger(Level l)
creates a new Logger-object with LogMode::Global and given local log-level
Definition: Logger.h:128
static void globalStatisticMode(bool s)
sets whether we are globally in statistic mode
Definition: Logger.h:249
Level m_loglevel
Definition: Logger.h:282
static Level globalInternalLibraryLogLevel()
gives the internal-library log-level
Definition: Logger.h:233
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
static Level m_minimumloglevel
Definition: Logger.h:279
static void setWorldStream(std::ostream &o)
change the stream to which allowed output is written (by default: cout)
Definition: Logger.h:252
static void globalInternalLibraryLogLevel(Level l)
sets the internal-library log-level
Definition: Logger.h:235
static Level globalLogLevel()
gives the global log-level
Definition: Logger.h:224
Logger(LogMode m, Level l)
creates a new Logger-object with given log-mode and given local log-level
Definition: Logger.h:130
static std::ostream nirvana
Definition: Logger.h:274
static std::ostream & slout(Level l=Level::Default)
stream for logging-output (global)
Definition: Logger.h:168
void localLogMode(LogMode m)
sets the local log-mode
Definition: Logger.h:215
the object is in logging mode, using its own localLogLevel
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
static Level globalMinimumLogLevel()
gives the globally minimally required log-level
Definition: Logger.h:238
static bool is_ilout(Level l=Level::Default)
stream for logging-output (global; used by internal libraries, e.g. Abacus) returns true if such an i...
Definition: Logger.h:186
Centralized global and local logging facility working on streams like cout.
Definition: Logger.h:99
Level
supported log-levels from lowest to highest importance
Definition: Logger.h:103
LogMode localLogMode() const
gives the local log-mode
Definition: Logger.h:211
static void globalMinimumLogLevel(Level l)
sets the globally minimally required log-level
Definition: Logger.h:240
The namespace for all OGDF objects.
the object is in statistic mode
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
Logger()
creates a new Logger-object with LogMode::Global and local log-level equal globalLogLevel ...
Definition: Logger.h:124
static std::ostream & ssout()
stream for statistic-output (global)
Definition: Logger.h:172
static std::ostream & ilout(Level l=Level::Default)
Definition: Logger.h:189
static Level m_globallibraryloglevel
Definition: Logger.h:278
the object is in the same mode as the static Logger-class (i.e., global settings) ...