Open Lighting Architecture 0.10.9
Loading...
Searching...
No Matches
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
15 *
16 * Logging.h
17 * Header file for the logging
18 * Copyright (C) 2005 Simon Newton
19 */
44#ifndef INCLUDE_OLA_LOGGING_H_
45#define INCLUDE_OLA_LOGGING_H_
46
47#include <ostream>
48#include <string>
49#include <sstream>
50
57#define OLA_LOG(level) (level <= ola::LogLevel()) && \
58 ola::LogLine(__FILE__, __LINE__, level).stream()
65#define OLA_FATAL OLA_LOG(ola::OLA_LOG_FATAL)
66
73#define OLA_WARN OLA_LOG(ola::OLA_LOG_WARN)
74
81#define OLA_INFO OLA_LOG(ola::OLA_LOG_INFO)
82
89#define OLA_DEBUG OLA_LOG(ola::OLA_LOG_DEBUG)
90
91namespace ola {
92
106
111extern log_level logging_level;
112
116typedef enum {
119 OLA_LOG_NULL,
120} log_output;
121
127 public:
131 virtual ~LogDestination() {}
132
138 virtual void Write(log_level level, const std::string &log_line) = 0;
139};
140
145 public:
149 void Write(log_level level, const std::string &log_line);
150};
151
156 public:
161
165 virtual bool Init() = 0;
166
171 virtual void Write(log_level level, const std::string &log_line) = 0;
172};
173
174#ifdef _WIN32
178class WindowsSyslogDestination : public SyslogDestination {
179 public:
183 bool Init();
184
188 void Write(log_level level, const std::string &log_line);
189 private:
190 typedef void* WindowsLogHandle;
191 WindowsLogHandle m_eventlog;
192};
193#else
198 public:
202 bool Init();
203
207 void Write(log_level level, const std::string &log_line);
208};
209#endif // _WIN32
210
218class LogLine {
219 public:
220 LogLine(const char *file, int line, log_level level);
221 ~LogLine();
222 void Write();
223
224 std::ostream &stream() { return m_stream; }
225 private:
226 log_level m_level;
227 std::ostringstream m_stream;
228 unsigned int m_prefix_length;
229};
241void SetLogLevel(log_level level);
242
247inline log_level LogLevel() { return logging_level; }
248
252void IncrementLogLevel();
253
260
267bool InitLogging(log_level level, log_output output);
268
274void InitLogging(log_level level, LogDestination *destination);
275/***/
276} // namespace ola
278#endif // INCLUDE_OLA_LOGGING_H_
The base class for log destinations.
Definition Logging.h:126
A LogDestination that writes to stderr.
Definition Logging.h:144
An abstract base of LogDestination that writes to syslog.
Definition Logging.h:155
A SyslogDestination that writes to Unix syslog.
Definition Logging.h:197
void Write(log_level level, const std::string &log_line)
Writes a messages out to stderr.
Definition Logging.cpp:185
bool Init()
Initialize the UnixSyslogDestination.
Definition Logging.cpp:233
@ OLA_LOG_FATAL
Definition Logging.h:100
@ OLA_LOG_DEBUG
Definition Logging.h:103
@ OLA_LOG_INFO
Definition Logging.h:102
@ OLA_LOG_WARN
Definition Logging.h:101
@ OLA_LOG_NONE
Definition Logging.h:99
bool InitLoggingFromFlags()
Initialize the OLA logging system from flags.
Definition Logging.cpp:83
void IncrementLogLevel()
Increment the log level by one. The log level wraps to OLA_LOG_NONE.
Definition Logging.cpp:76
virtual bool Init()=0
Initialize the SyslogDestination.
void SetLogLevel(log_level level)
Set the logging level.
Definition Logging.cpp:71
virtual void Write(log_level level, const std::string &log_line)=0
Write a line to the system logger.
void Write(log_level level, const std::string &log_line)
Write a line to syslog.
Definition Logging.cpp:237
virtual ~LogDestination()
Destructor.
Definition Logging.h:131
log_level LogLevel()
Fetch the current level of logging.
Definition Logging.h:247
virtual void Write(log_level level, const std::string &log_line)=0
An abstract function for writing to your log destination.
virtual ~SyslogDestination()
Destructor.
Definition Logging.h:160
@ OLA_LOG_STDERR
Definition Logging.h:117
@ OLA_LOG_SYSLOG
Definition Logging.h:118
bool InitLogging(log_level level, log_output output)
Initialize the OLA logging system.
Definition Logging.cpp:118
The namespace containing all OLA symbols.
Definition Credentials.cpp:44
log_level
The OLA log levels. This controls the verbosity of logging. Each level also includes those below it.
Definition Logging.h:98
log_output
The destination to write log messages to.
Definition Logging.h:116