Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

Loading...
Searching...
No Matches
Logger.h
Go to the documentation of this file.
1
32#pragma once
33
35
36#include <algorithm>
37
38namespace ogdf {
39
41
100class Logger {
101public:
103 enum class Level { Minor, Medium, Default, High, Alarm, Force };
105 enum class LogMode {
107 Global,
109 GlobalLog,
111 Log,
114 };
115
118
120 explicit Logger(LogMode m) : Logger(m, m_globalloglevel) { }
121
123 explicit Logger(Level level) : Logger(LogMode::Global, level) { }
124
126 Logger(LogMode m, Level level) : m_loglevel(level), m_logmode(m) { }
127
130
132 bool is_lout(Level level = Level::Default) const {
135 return level >= m_globalloglevel;
136 } else {
137 return m_logmode == LogMode::Log && level >= std::max(m_loglevel, m_minimumloglevel);
138 }
139 }
140
142 std::ostream& lout(Level level = Level::Default) const {
143 return is_lout(level) ? *world : nirvana;
144 }
145
147 std::ostream& sout() const {
150 ? *world
151 : nirvana;
152 }
153
155 std::ostream& fout() const { return sfout(); }
156
160
162 static bool is_slout(Level level = Level::Default) {
163 return !m_globalstatisticmode && level >= m_globalloglevel;
164 }
165
167 static std::ostream& slout(Level level = Level::Default) {
168 return is_slout(level) ? *world : nirvana;
169 }
170
172 static std::ostream& ssout() { return m_globalstatisticmode ? *world : nirvana; }
173
175 static std::ostream& sfout() { return *world; }
176
180
183 static bool is_ilout(Level level = Level::Default) {
185 }
186
187 static std::ostream& ilout(Level level = Level::Default) {
188 return is_ilout(level) ? *world : nirvana;
189 }
190
192 static std::ostream& ifout() { return *world; }
193
197
199 Level localLogLevel() const { return m_loglevel; }
200
202 void localLogLevel(Level level) { m_loglevel = level; }
203
205 LogMode localLogMode() const { return m_logmode; }
206
209
213
216
218 static void globalLogLevel(Level level) {
219 m_globalloglevel = level;
222 }
223 }
224
227
230
233
241
244
246 static void globalStatisticMode(bool s) { m_globalstatisticmode = s; }
247
249 static void setWorldStream(std::ostream& o) { world = &o; }
250
254
258 return m_globalloglevel;
259 } else {
261 }
262 }
263
269
271
272private:
273 static OGDF_EXPORT std::ostream nirvana;
274 static OGDF_EXPORT std::ostream* world;
275
280
283};
284
285inline std::ostream& operator<<(std::ostream& os, Logger::Level level) {
286 switch (level) {
288 os << "Minor";
289 break;
291 os << "Medium";
292 break;
294 os << "Default";
295 break;
297 os << "High";
298 break;
300 os << "Alarm";
301 break;
303 os << "Force";
304 break;
305 }
306 return os;
307}
308
309}
Centralized global and local logging facility working on streams like std::cout.
Definition Logger.h:100
std::ostream & sout() const
stream for statistic-output (local)
Definition Logger.h:147
static std::ostream * world
Definition Logger.h:274
Logger(Level level)
creates a new Logger-object with LogMode::Global and given local log-level
Definition Logger.h:123
static void globalInternalLibraryLogLevel(Level level)
sets the internal-library log-level
Definition Logger.h:229
static Level globalInternalLibraryLogLevel()
gives the internal-library log-level
Definition Logger.h:226
static std::ostream & sfout()
stream for forced output (global)
Definition Logger.h:175
static std::ostream & ssout()
stream for statistic-output (global)
Definition Logger.h:172
static void globalMinimumLogLevel(Level level)
sets the globally minimally required log-level
Definition Logger.h:235
static void globalLogLevel(Level level)
sets the global log-level
Definition Logger.h:218
void localLogLevel(Level level)
sets the local log-level
Definition Logger.h:202
static bool is_slout(Level level=Level::Default)
returns true if such an slout command will result in text being printed
Definition Logger.h:162
void localLogMode(LogMode m)
sets the local log-mode
Definition Logger.h:208
std::ostream & fout() const
stream for forced output (local)
Definition Logger.h:155
LogMode m_logmode
Definition Logger.h:282
static std::ostream nirvana
Definition Logger.h:273
Level m_loglevel
Definition Logger.h:281
Logger(LogMode m)
creates a new Logger-object with given log-mode and local log-level equal globalLogLevel
Definition Logger.h:120
static Level m_globallibraryloglevel
Definition Logger.h:277
static Level globalLogLevel()
gives the global log-level
Definition Logger.h:215
static bool globalStatisticMode()
returns true if we are globally in statistic mode
Definition Logger.h:243
Level localLogLevel() const
gives the local log-level
Definition Logger.h:199
static Level m_globalloglevel
Definition Logger.h:276
Level
supported log-levels from lowest to highest importance
Definition Logger.h:103
LogMode
Local log-modes.
Definition Logger.h:105
@ GlobalLog
the object is in logging mode, but uses the globalLogLevel
@ Statistic
the object is in statistic mode
@ Global
the object is in the same mode as the static Logger-class (i.e., global settings)
@ Log
the object is in logging mode, using its own localLogLevel
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:183
static std::ostream & ilout(Level level=Level::Default)
Definition Logger.h:187
static std::ostream & slout(Level level=Level::Default)
stream for logging-output (global)
Definition Logger.h:167
Logger()
creates a new Logger-object with LogMode::Global and local log-level equal globalLogLevel
Definition Logger.h:117
static std::ostream & ifout()
stream for forced output (global; used by internal libraries, e.g. Abacus)
Definition Logger.h:192
LogMode localLogMode() const
gives the local log-mode
Definition Logger.h:205
std::ostream & lout(Level level=Level::Default) const
stream for logging-output (local)
Definition Logger.h:142
static bool m_globalstatisticmode
Definition Logger.h:279
static Level m_minimumloglevel
Definition Logger.h:278
static Level globalMinimumLogLevel()
gives the globally minimally required log-level
Definition Logger.h:232
Level effectiveLogLevel() const
obtain the effective log-level for the Logger-object (i.e., resolve the dependencies on the global se...
Definition Logger.h:256
static void setWorldStream(std::ostream &o)
change the stream to which allowed output is written (by default: std::cout)
Definition Logger.h:249
bool is_lout(Level level=Level::Default) const
returns true if such an lout command will result in text being printed
Definition Logger.h:132
bool effectiveStatisticMode() const
returns true if the Logger-object is effectively in statistic-mode (as this might be depending on the...
Definition Logger.h:265
Logger(LogMode m, Level level)
creates a new Logger-object with given log-mode and given local log-level
Definition Logger.h:126
static void globalStatisticMode(bool s)
sets whether we are globally in statistic mode
Definition Logger.h:246
Basic configuration file.
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition config.h:101
static MultilevelBuilder * getDoubleFactoredZeroAdjustedMerger()
The namespace for all OGDF objects.
std::ostream & operator<<(std::ostream &os, const ogdf::Array< E, INDEX > &a)
Prints array a to output stream os.
Definition Array.h:978