Open Lighting Architecture
Main Page
Modules
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
include
ola
Logging.h
Go to the documentation of this file.
1
/*
2
* This library is free software; you can redistribute it and/or
3
* modify it under the terms of the GNU Lesser General Public
4
* License as published by the Free Software Foundation; either
5
* version 2.1 of the License, or (at your option) any later version.
6
*
7
* This library is distributed in the hope that it will be useful,
8
* but WITHOUT ANY WARRANTY; without even the implied warranty of
9
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10
* Lesser General Public License for more details.
11
*
12
* You should have received a copy of the GNU Lesser General Public
13
* License along with this library; if not, write to the Free Software
14
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
*
16
* Logging.h
17
* Header file for the logging
18
* Copyright (C) 2005-2009 Simon Newton
19
*/
44
#ifndef INCLUDE_OLA_LOGGING_H_
45
#define INCLUDE_OLA_LOGGING_H_
46
47
#ifdef WIN32
48
#include <windows.h>
// for HANDLE
49
#endif
50
51
#include <ostream>
52
#include <string>
53
#include <sstream>
54
61
#define OLA_LOG(level) (level <= ola::LogLevel()) && \
62
ola::LogLine(__FILE__, __LINE__, level).stream()
63
69
#define OLA_FATAL OLA_LOG(ola::OLA_LOG_FATAL)
70
77
#define OLA_WARN OLA_LOG(ola::OLA_LOG_WARN)
78
85
#define OLA_INFO OLA_LOG(ola::OLA_LOG_INFO)
86
93
#define OLA_DEBUG OLA_LOG(ola::OLA_LOG_DEBUG)
94
95
namespace
ola {
96
97
using
std::string;
98
104
enum
log_level
{
105
OLA_LOG_NONE
,
106
OLA_LOG_FATAL
,
107
OLA_LOG_WARN
,
108
OLA_LOG_INFO
,
109
OLA_LOG_DEBUG
,
110
OLA_LOG_MAX,
111
};
112
117
extern
log_level
logging_level
;
118
122
typedef
enum
{
123
OLA_LOG_STDERR
,
124
OLA_LOG_SYSLOG
,
125
OLA_LOG_NULL,
126
}
log_output
;
127
132
class
LogDestination
{
133
public
:
137
virtual
~LogDestination
() {}
138
144
virtual
void
Write
(
log_level
level,
const
string
&log_line) = 0;
145
};
146
150
class
StdErrorLogDestination
:
public
LogDestination
{
151
public
:
155
void
Write
(
log_level
level,
const
string
&log_line);
156
};
157
161
class
SyslogDestination
:
public
LogDestination
{
162
public
:
166
bool
Init
();
167
172
void
Write
(
log_level
level,
const
string
&log_line);
173
private
:
174
#ifdef WIN32
175
HANDLE m_eventlog;
176
#endif
177
};
178
186
class
LogLine {
187
public
:
188
LogLine(
const
char
*file,
int
line,
log_level
level);
189
~LogLine();
190
void
Write();
191
192
std::ostream &stream() {
return
m_stream; }
193
private
:
194
log_level
m_level;
195
std::ostringstream m_stream;
196
unsigned
int
m_prefix_length;
197
};
209
void
SetLogLevel
(
log_level
level);
210
215
inline
log_level
LogLevel
() {
return
logging_level
; }
216
220
void
IncrementLogLevel
();
221
227
bool
InitLoggingFromFlags
();
228
235
bool
InitLogging
(
log_level
level,
log_output
output);
236
243
void
InitLogging
(
log_level
level, LogDestination *destination);
244
/***/
245
}
// namespace ola
247
#endif // INCLUDE_OLA_LOGGING_H_
Generated on Fri Apr 4 2014 11:54:22 for Open Lighting Architecture by
1.8.1.2