Carna
Version 3.3.2
include
Carna
base
Log.h
Go to the documentation of this file.
1
/*
2
* Copyright (C) 2010 - 2015 Leonid Kostrykin
3
*
4
* Chair of Medical Engineering (mediTEC)
5
* RWTH Aachen University
6
* Pauwelsstr. 20
7
* 52074 Aachen
8
* Germany
9
*
10
*/
11
12
#ifndef LOG_H_6014714286
13
#define LOG_H_6014714286
14
15
#include <Carna/Carna.h>
16
#include <
Carna/base/Singleton.h
>
17
#include <
Carna/base/noncopyable.h
>
18
#include <functional>
19
#include <string>
20
#include <memory>
21
26
namespace
Carna
27
{
28
29
namespace
base
30
{
31
32
33
34
// ----------------------------------------------------------------------------------
35
// Log
36
// ----------------------------------------------------------------------------------
37
46
class
CARNA_LIB
Log
:
public
Singleton
< Log >
47
{
48
49
struct
Details;
50
const
std::unique_ptr< Details > pimpl;
51
52
NON_COPYABLE
53
54
void
pushTag(
const
std::string& tag );
55
56
void
popTag();
57
58
protected
:
59
60
friend
class
Singleton
< Log >;
61
65
Log();
66
67
public
:
68
73
virtual
~Log();
74
78
const
std::string& tag()
const
;
79
83
enum
Severity
84
{
85
fatal
,
86
error
,
87
warning
,
88
debug
,
89
verbose
90
};
91
92
// ------------------------------------------------------------------------------
93
// Log :: TagScope
94
// ------------------------------------------------------------------------------
95
104
struct
CARNA_LIB
TagScope
105
{
110
explicit
TagScope
(
const
std::string& tag );
111
115
~TagScope();
116
117
private
:
118
119
const
bool
valid;
120
static
void
*
operator
new
( std::size_t );
121
static
void
*
operator
new
[]( std::size_t );
122
};
123
124
// ------------------------------------------------------------------------------
125
// Log :: Writer
126
// ------------------------------------------------------------------------------
127
134
class
CARNA_LIB
Writer
135
{
136
137
NON_COPYABLE
138
139
public
:
140
144
virtual
~
Writer
();
145
149
virtual
void
write(
Severity
severity,
const
std::string& entry )
const
= 0;
150
151
};
// Log :: Writer
152
153
// ------------------------------------------------------------------------------
154
// Log :: TextWriter
155
// ------------------------------------------------------------------------------
156
164
class
CARNA_LIB
TextWriter
:
public
Writer
165
{
166
167
public
:
168
169
virtual
void
write(
Severity
,
const
std::string& )
const override
;
170
171
protected
:
172
176
virtual
void
writeLine(
Severity
severity,
const
std::string& formattedEntry )
const
= 0;
177
178
};
// Log :: TextWriter
179
180
// ------------------------------------------------------------------------------
181
// Log :: StdWriter
182
// ------------------------------------------------------------------------------
183
191
class
CARNA_LIB
StdWriter
:
public
TextWriter
192
{
193
194
protected
:
195
196
virtual
void
writeLine(
Severity
,
const
std::string& )
const override
;
197
198
};
// Log :: StdWriter
199
203
void
setWriter(
Writer
* );
204
208
void
record(
Severity
severity,
const
std::string& entry )
const
;
209
210
// ------------------------------------------------------------------------------
211
// Log :: OnShutdownListener
212
// ------------------------------------------------------------------------------
213
221
class
CARNA_LIB
OnShutdownListener
222
{
223
224
public
:
225
229
virtual
~
OnShutdownListener
();
230
234
virtual
void
onLogShutdown() = 0;
235
236
};
// Log :: OnShutdownListener
237
241
void
addOnShutdownListener(
OnShutdownListener
& listener );
242
247
void
removeOnShutdownListener(
const
OnShutdownListener
& listener );
248
256
void
shutdown();
257
258
};
// Log
259
260
261
262
// ----------------------------------------------------------------------------------
263
// CARNA_LOG_TAG_SCOPE
264
// ----------------------------------------------------------------------------------
265
269
#define CARNA_LOG_TAG_SCOPE( tag ) \
270
const ::Carna::base::Log::TagScope _tagScope##__COUNTER__( tag )
271
272
273
274
}
// namespace Carna :: base
275
276
}
// namespace Carna
277
278
#endif // LOG_H_6014714286
Carna::base::Log::StdWriter
Writes fatal and error classified log messages to std::cerr and such classified as warning or debug t...
Definition:
Log.h:191
Carna::base::Log::error
Indicates errors like memory leaks.
Definition:
Log.h:86
Carna::base::Log::fatal
Indicates errors that might lead to misbehaving program logic.
Definition:
Log.h:85
Carna::base::Log::Writer
Writes log entries.
Definition:
Log.h:134
Carna::base::Singleton
Singleton base class
Definition:
Singleton.h:59
Carna::base::Log::debug
Indicates messages that might be of interest when searching bugs.
Definition:
Log.h:88
Carna::base::Log::Severity
Severity
Describes the severity of a log entry.
Definition:
Log.h:83
Carna::base::Log::OnShutdownListener
Defines callback interface that is invoked when the Log system is about to shut down.
Definition:
Log.h:221
Carna::base::Log::warning
Indicates warnings.
Definition:
Log.h:87
Singleton.h
Defines Carna::base::Singleton.
Carna::base::Log
Records log messages. The log writing is delegated to implementations of the Log::Writer interface...
Definition:
Log.h:46
Carna
Definition:
doc_CoordinateSystems.dox:1
Carna::base::Log::TagScope
Enforces the log to use a specific tag for the duration of the existence of the object from this clas...
Definition:
Log.h:104
noncopyable.h
Carna::base::Log::TextWriter
Abstract implementation of the Writer interface, that formats log messages along with their severity ...
Definition:
Log.h:164
NON_COPYABLE
#define NON_COPYABLE
Features class it is placed in as non-copyable.
Definition:
noncopyable.h:109
Written by
Leonid Kostrykin
at the Chair of Medical Engineering (mediTEC), RWTH Aachen University
Documentation generated by
Doxygen