OpenWalnut
1.2.5
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
All
Classes
Namespaces
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
src
core
common
WLogEntry.h
1
//---------------------------------------------------------------------------
2
//
3
// Project: OpenWalnut ( http://www.openwalnut.org )
4
//
5
// Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6
// For more information see http://www.openwalnut.org/copying
7
//
8
// This file is part of OpenWalnut.
9
//
10
// OpenWalnut is free software: you can redistribute it and/or modify
11
// it under the terms of the GNU Lesser General Public License as published by
12
// the Free Software Foundation, either version 3 of the License, or
13
// (at your option) any later version.
14
//
15
// OpenWalnut is distributed in the hope that it will be useful,
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
// GNU Lesser General Public License for more details.
19
//
20
// You should have received a copy of the GNU Lesser General Public License
21
// along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22
//
23
//---------------------------------------------------------------------------
24
25
#ifndef WLOGENTRY_H
26
#define WLOGENTRY_H
27
28
#include <string>
29
30
#include "WTerminalColor.h"
31
#include "WExportCommon.h"
32
33
/**
34
* Various log levels, to distinguish output on its level.
35
*/
36
typedef
enum
37
{
38
LL_DEBUG = 0,
39
LL_INFO,
40
LL_WARNING,
41
LL_ERROR
42
}
43
LogLevel;
44
45
/**
46
* Simple function to convert a given string to an log level. If the string is invalid, LL_DEBUG is returned.
47
*
48
* \param str the string containing the log level string-representation
49
* \return the loglevel
50
*/
51
LogLevel logLevelFromString(
const
std::string& str );
52
53
/**
54
* Represents a simple log message with some attributes.
55
*/
56
class
OWCOMMON_EXPORT
WLogEntry
// NOLINT
57
{
58
public
:
59
60
/**
61
* Creates a new log message.
62
*
63
* \param logTime the time
64
* \param message the message
65
* \param level the log level
66
* \param source the source, sending the log
67
*/
68
WLogEntry
( std::string logTime, std::string message, LogLevel level, std::string source =
""
);
69
70
/**
71
* Destroys a log message entry.
72
*/
73
virtual
~
WLogEntry
();
74
75
/**
76
* \param format A string describing the output format in c printf style
77
* \param colors True if colors should be used. True is the default.
78
*
79
* \return String of this log entry.
80
*/
81
std::string getLogString( std::string format =
"[%t] *%l* %m \n"
,
bool
colors =
true
)
const
;
82
83
/**
84
* \return log level of this entry.
85
*/
86
LogLevel getLogLevel()
const
;
87
88
/**
89
* Returns the plain message of the entry.
90
*
91
* \return the message
92
*/
93
std::string getMessage()
const
;
94
95
/**
96
* Returns the sender of the log.
97
*
98
* \return sender
99
*/
100
std::string getSource()
const
;
101
102
/**
103
* Returns the formatted time string.
104
*
105
* \return time string
106
*/
107
std::string getTime()
const
;
108
109
protected
:
110
private
:
111
/**
112
* The time the log message was received
113
*/
114
std::string
m_time
;
115
116
/**
117
* The actual message
118
*/
119
std::string
m_message
;
120
121
/**
122
* Log level
123
*/
124
LogLevel
m_level
;
125
126
/**
127
* Source (e.g. module name) where this log message comes from.
128
*/
129
std::string
m_source
;
130
131
/**
132
* Color used for error logs.
133
*
134
* \note it is mutable to allow en-/disabling the colors during getLogString.
135
*/
136
mutable
WTerminalColor
m_errorColor
;
137
138
/**
139
* Color used for info logs
140
*
141
* \note it is mutable to allow en-/disabling the colors during getLogString.
142
*/
143
mutable
WTerminalColor
m_infoColor
;
144
145
/**
146
* Color used for debug logs.
147
*
148
* \note it is mutable to allow en-/disabling the colors during getLogString.
149
*/
150
mutable
WTerminalColor
m_debugColor
;
151
152
/**
153
* Color used for warning logs.
154
*
155
* \note it is mutable to allow en-/disabling the colors during getLogString.
156
*/
157
mutable
WTerminalColor
m_warningColor
;
158
159
/**
160
* Color used for source field.
161
*
162
* \note it is mutable to allow en-/disabling the colors during getLogString.
163
*/
164
mutable
WTerminalColor
m_sourceColor
;
165
166
/**
167
* Color used for time.
168
*
169
* \note it is mutable to allow en-/disabling the colors during getLogString.
170
*/
171
mutable
WTerminalColor
m_timeColor
;
172
173
/**
174
* Color used for the message.
175
*
176
* \note it is mutable to allow en-/disabling the colors during getLogString.
177
*/
178
mutable
WTerminalColor
m_messageColor
;
179
};
180
181
#endif // WLOGENTRY_H
182
Generated by
1.8.1.2