Lightmetrica  0.0.1.50dbee3 (yosakoi)
 All Classes Functions Variables Typedefs Enumerations Enumerator
logger.h
1 /*
2  Lightmetrica : A research-oriented renderer
3 
4  Copyright (c) 2014 Hisanari Otsu
5 
6  This program is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 #ifndef LIB_LIGHTMETRICA_LOGGER_H
22 #define LIB_LIGHTMETRICA_LOGGER_H
23 
24 #include "common.h"
25 #include <string>
26 #include <memory>
27 #include <functional>
28 #include <boost/signals2.hpp>
29 
30 LM_NAMESPACE_BEGIN
31 
36 class LM_PUBLIC_API Logger
37 {
38 public:
39 
46  {
47  Signal = 1<<0,
48  Stdout = 1<<1,
49  Stderr = 1<<2,
50  File = 1<<3,
51  FileHtml = 1<<4,
52  DebugOutput = 1<<5,
53 
54  NoFileOutput = Signal | Stdout | Stderr | DebugOutput,
55  FileOutput = File | FileHtml,
56  };
57 
62  enum class LogUpdateMode
63  {
64  Manual,
65  Immediate,
66  };
67 
72  enum class LogLevel
73  {
74  Error,
75  Warning,
76  Information,
77  Debug,
78  };
79 
80  /*
81  Log entry.
82  The entry of the log message.
83  */
84  struct LogEntry
85  {
87  std::string time;
88  std::string message;
89  };
90 
91 private:
92 
93  Logger();
94  ~Logger();
95 
96  LM_DISABLE_COPY_AND_MOVE(Logger);
97 
98 public:
99 
106  static boost::signals2::connection Connect_LogUpdate(const std::function<void (LogEntry*)>& func);
107 
108 public:
109 
113  static void Reset();
114 
118  static void Clear();
119 
125  static void Error(const std::string& message, const std::string& prefix);
126 
132  static void Warn(const std::string& message, const std::string& prefix);
133 
139  static void Info(const std::string& message, const std::string& prefix);
140 
146  static void Debug(const std::string& message, const std::string& prefix);
147 
152  static int CountNoFileOutputEntries();
153 
158  static int CountFileOutputEntries();
159 
165  static void SetUpdateMode(LogUpdateMode mode);
166 
172  static void SetOutputMode(int mode);
173 
180  static void SetOutputFrequency(int freq);
181 
188  static void SetOutputFrequencyForFileOutput(int freq);
189 
196  static void SetOutputFileName(const std::string& fileName);
197 
204  static std::string FormattedDebugInfo(const char* fileName, int line);
205 
211  static void ProcessOutput();
212 
218  static bool Empty();
219 
224  static unsigned int Indentation();
225 
230  static void SetIndentation(unsigned int indentation);
231 
232 };
233 
239 {
240 public:
241 
244 
245 private:
246 
247  LM_DISABLE_COPY_AND_MOVE(LogIndenter);
248 
249 };
250 
251 LM_NAMESPACE_END
252 
283 #if LM_DEBUG_MODE
284  #define LM_LOG_ERROR(message) lightmetrica::Logger::Error(message, lightmetrica::Logger::FormattedDebugInfo(__FILE__, __LINE__));
285  #define LM_LOG_WARN(message) lightmetrica::Logger::Warn(message, lightmetrica::Logger::FormattedDebugInfo(__FILE__, __LINE__));
286  #define LM_LOG_INFO(message) lightmetrica::Logger::Info(message, lightmetrica::Logger::FormattedDebugInfo(__FILE__, __LINE__));
287  #define LM_LOG_DEBUG(message) lightmetrica::Logger::Debug(message, lightmetrica::Logger::FormattedDebugInfo(__FILE__, __LINE__));
288 #else
289  #define LM_LOG_ERROR(message) lightmetrica::Logger::Error(message, "");
290  #define LM_LOG_WARN(message) lightmetrica::Logger::Warn(message, "");
291  #define LM_LOG_INFO(message) lightmetrica::Logger::Info(message, "");
292  #define LM_LOG_DEBUG(message) lightmetrica::Logger::Debug(message, "");
293 #endif
294 #define LM_LOG_INDENTER() lightmetrica::LogIndenter _logIndenter;
295 
296 #endif // LIB_LIGHTMETRICA_LOGGER_H
Definition: logger.h:36
LogUpdateMode
Definition: logger.h:62
std::string time
Current time.
Definition: logger.h:87
LogLevel
Definition: logger.h:72
LogOutputMode
Definition: logger.h:45
LogLevel level
Associated log level.
Definition: logger.h:86
std::string message
Log message.
Definition: logger.h:88
Definition: logger.h:84
Definition: logger.h:238
static void SetIndentation(unsigned int indentation)
Definition: logger.cpp:479
static unsigned int Indentation()
Definition: logger.cpp:473