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
34#include <ogdf/basic/basic.h>
35
36#include <algorithm>
37#include <ostream>
38#include <string>
39
40namespace ogdf {
41
43
102class Logger {
103public:
105 enum class Level { Minor, Medium, Default, High, Alarm, Force };
107 enum class LogMode {
109 Global,
111 GlobalLog,
113 Log,
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
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
250
252 static void globalLogLevel(Level level) {
253 m_globalloglevel = level;
256 }
257 }
258
261
264
267
275
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
303
305
306private:
307 static OGDF_EXPORT std::ostream nirvana;
308 static OGDF_EXPORT std::ostream* world;
309
314
318};
319
320inline 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;
332 os << "High";
333 break;
335 os << "Alarm";
336 break;
338 os << "Force";
339 break;
340 }
341 return os;
342}
343
344}
Basic declarations, included by all source files.
Indent & operator=(const Indent &other)=delete
Indent(Logger &log, int by=1)
Definition Logger.h:125
Indent(Logger *log, int by=1)
Definition Logger.h:123
Indent(const Indent &copy)=delete
Centralized global and local logging facility working on streams like std::cout.
Definition Logger.h:102
std::ostream & sout() const
stream for statistic-output (local)
Definition Logger.h:173
static std::ostream * world
Definition Logger.h:308
Logger(Level level)
creates a new Logger-object with LogMode::Log and given local log-level
Definition Logger.h:141
int getIndent() const
Definition Logger.h:240
static void globalInternalLibraryLogLevel(Level level)
sets the internal-library log-level
Definition Logger.h:263
static Level globalInternalLibraryLogLevel()
gives the internal-library log-level
Definition Logger.h:260
static std::ostream & sfout()
stream for forced output (global)
Definition Logger.h:201
static std::ostream & ssout()
stream for statistic-output (global)
Definition Logger.h:198
static void globalMinimumLogLevel(Level level)
sets the globally minimally required log-level
Definition Logger.h:269
static void globalLogLevel(Level level)
sets the global log-level
Definition Logger.h:252
void localLogLevel(Level level)
sets the local log-level
Definition Logger.h:228
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
int m_indent
Definition Logger.h:317
void localLogMode(LogMode m)
sets the local log-mode
Definition Logger.h:234
std::ostream & fout() const
stream for forced output (local)
Definition Logger.h:181
void indent(int by=1)
Definition Logger.h:236
LogMode m_logmode
Definition Logger.h:316
static std::ostream nirvana
Definition Logger.h:307
Level m_loglevel
Definition Logger.h:315
void setIndent(int indent)
Definition Logger.h:242
Logger(LogMode m)
creates a new Logger-object with given log-mode and local log-level equal globalLogLevel
Definition Logger.h:138
static Level m_globallibraryloglevel
Definition Logger.h:311
static Level globalLogLevel()
gives the global log-level
Definition Logger.h:249
static bool globalStatisticMode()
returns true if we are globally in statistic mode
Definition Logger.h:277
void dedent(int by=1)
Definition Logger.h:238
std::ostream & lout(Level level=Level::Default, bool indent=true) const
stream for logging-output (local)
Definition Logger.h:160
Level localLogLevel() const
gives the local log-level
Definition Logger.h:225
static Level m_globalloglevel
Definition Logger.h:310
Level
supported log-levels from lowest to highest importance
Definition Logger.h:105
LogMode
Local log-modes.
Definition Logger.h:107
@ 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:209
static std::ostream & ilout(Level level=Level::Default)
Definition Logger.h:213
static std::ostream & slout(Level level=Level::Default)
stream for logging-output (global)
Definition Logger.h:193
Logger()
creates a new Logger-object with LogMode::Global and local log-level equal globalLogLevel
Definition Logger.h:135
static std::ostream & ifout()
stream for forced output (global; used by internal libraries, e.g. Abacus)
Definition Logger.h:218
LogMode localLogMode() const
gives the local log-mode
Definition Logger.h:231
static bool m_globalstatisticmode
Definition Logger.h:313
static Level m_minimumloglevel
Definition Logger.h:312
static Level globalMinimumLogLevel()
gives the globally minimally required log-level
Definition Logger.h:266
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
static void setWorldStream(std::ostream &o)
change the stream to which allowed output is written (by default: std::cout)
Definition Logger.h:283
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
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
Logger(LogMode m, Level level)
creates a new Logger-object with given log-mode and given local log-level
Definition Logger.h:144
static void globalStatisticMode(bool s)
sets whether we are globally in statistic mode
Definition Logger.h:280
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF dynamic library (shared object / DLL),...
Definition config.h:117
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:983