Open Lighting Architecture  0.10.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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()
59 
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 
91 namespace ola {
92 
98 enum log_level {
104  OLA_LOG_MAX,
105 };
106 
111 extern log_level logging_level;
112 
116 typedef 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:
160  virtual ~SyslogDestination() {}
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
175 
178 class 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
194 
198  public:
202  bool Init();
203 
207  void Write(log_level level, const std::string &log_line);
208 };
209 #endif // _WIN32
210 
218 class 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 };
241 void SetLogLevel(log_level level);
242 
247 inline log_level LogLevel() { return logging_level; }
248 
252 void IncrementLogLevel();
253 
259 bool InitLoggingFromFlags();
260 
267 bool InitLogging(log_level level, log_output output);
268 
274 void InitLogging(log_level level, LogDestination *destination);
275 /***/
276 } // namespace ola
278 #endif // INCLUDE_OLA_LOGGING_H_
log_output
The destination to write log messages to.
Definition: Logging.h:116
log_level
The OLA log levels. This controls the verbosity of logging. Each level also includes those below it...
Definition: Logging.h:98
Definition: Logging.h:103
void Write(log_level level, const std::string &log_line)
Write a line to syslog.
Definition: Logging.cpp:236
Definition: Logging.h:102
virtual void Write(log_level level, const std::string &log_line)=0
Write a line to the system logger.
void SetLogLevel(log_level level)
Set the logging level.
Definition: Logging.cpp:70
log_level LogLevel()
Fetch the current level of logging.
Definition: Logging.h:247
void IncrementLogLevel()
Increment the log level by one. The log level wraps to OLA_LOG_NONE.
Definition: Logging.cpp:75
A SyslogDestination that writes to Unix syslog.
Definition: Logging.h:197
Definition: Logging.h:117
An abstract base of LogDestination that writes to syslog.
Definition: Logging.h:155
virtual void Write(log_level level, const std::string &log_line)=0
An abstract function for writing to your log destination.
Definition: Logging.h:99
virtual ~SyslogDestination()
Destructor.
Definition: Logging.h:160
Definition: Logging.h:100
virtual ~LogDestination()
Destructor.
Definition: Logging.h:131
bool InitLogging(log_level level, log_output output)
Initialize the OLA logging system.
Definition: Logging.cpp:117
Definition: Logging.h:101
A LogDestination that writes to stderr.
Definition: Logging.h:144
virtual bool Init()=0
Initialize the SyslogDestination.
log_level logging_level
Application global logging level.
The namespace containing all OLA symbols.
Definition: Credentials.cpp:44
bool InitLoggingFromFlags()
Initialize the OLA logging system from flags.
Definition: Logging.cpp:82
Definition: Logging.h:118
bool Init()
Initialize the UnixSyslogDestination.
Definition: Logging.cpp:232
The base class for log destinations.
Definition: Logging.h:126
void Write(log_level level, const std::string &log_line)
Writes a messages out to stderr.
Definition: Logging.cpp:184