Open Lighting Architecture
0.9.0
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
102
enum
log_level
{
103
OLA_LOG_NONE
,
104
OLA_LOG_FATAL
,
105
OLA_LOG_WARN
,
106
OLA_LOG_INFO
,
107
OLA_LOG_DEBUG
,
108
OLA_LOG_MAX,
109
};
110
115
extern
log_level
logging_level
;
116
120
typedef
enum
{
121
OLA_LOG_STDERR
,
122
OLA_LOG_SYSLOG
,
123
OLA_LOG_NULL,
124
}
log_output
;
125
130
class
LogDestination
{
131
public
:
135
virtual
~LogDestination
() {}
136
142
virtual
void
Write
(
log_level
level,
const
std::string &log_line) = 0;
143
};
144
148
class
StdErrorLogDestination
:
public
LogDestination
{
149
public
:
153
void
Write
(
log_level
level,
const
std::string &log_line);
154
};
155
159
class
SyslogDestination
:
public
LogDestination
{
160
public
:
164
bool
Init
();
165
170
void
Write
(
log_level
level,
const
std::string &log_line);
171
private
:
172
#ifdef WIN32
173
HANDLE m_eventlog;
174
#endif
175
};
176
184
class
LogLine {
185
public
:
186
LogLine(
const
char
*file,
int
line,
log_level
level);
187
~LogLine();
188
void
Write();
189
190
std::ostream &stream() {
return
m_stream; }
191
private
:
192
log_level
m_level;
193
std::ostringstream m_stream;
194
unsigned
int
m_prefix_length;
195
};
207
void
SetLogLevel
(
log_level
level);
208
213
inline
log_level
LogLevel
() {
return
logging_level
; }
214
218
void
IncrementLogLevel
();
219
225
bool
InitLoggingFromFlags
();
226
233
bool
InitLogging
(
log_level
level,
log_output
output);
234
241
void
InitLogging
(
log_level
level, LogDestination *destination);
242
/***/
243
}
// namespace ola
245
#endif // INCLUDE_OLA_LOGGING_H_
Generated on Fri Apr 4 2014 11:46:03 for Open Lighting Architecture by
1.8.1.2