Open Lighting Architecture  0.9.1
 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:
158 
162  bool Init();
163 
168  void Write(log_level level, const std::string &log_line);
169 
170  private:
171  typedef void* WindowsLogHandle;
172  WindowsLogHandle m_eventlog;
173 };
174 
182 class LogLine {
183  public:
184  LogLine(const char *file, int line, log_level level);
185  ~LogLine();
186  void Write();
187 
188  std::ostream &stream() { return m_stream; }
189  private:
190  log_level m_level;
191  std::ostringstream m_stream;
192  unsigned int m_prefix_length;
193 };
205 void SetLogLevel(log_level level);
206 
211 inline log_level LogLevel() { return logging_level; }
212 
216 void IncrementLogLevel();
217 
223 bool InitLoggingFromFlags();
224 
231 bool InitLogging(log_level level, log_output output);
232 
239 void InitLogging(log_level level, LogDestination *destination);
240 /***/
241 } // namespace ola
243 #endif // INCLUDE_OLA_LOGGING_H_