Open Lighting Architecture  0.9.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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
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 
275 void InitLogging(log_level level, LogDestination *destination);
276 /***/
277 } // namespace ola
279 #endif // INCLUDE_OLA_LOGGING_H_