LBIBCell
 All Classes Functions Variables Friends Pages
Log.hpp
1 /* Copyright (c) 2013 David Sichau <mail"at"sichau"dot"eu>
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining a copy
4  * of this software and associated documentation files (the "Software"), to deal
5  * in the Software without restriction, including without limitation the rights
6  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7  * copies of the Software, and to permit persons to whom the Software is
8  * furnished to do so, subject to the following conditions:
9  *
10  * The above copyright notice and this permission notice shall be included in
11  * all copies or substantial portions of the Software.
12  *
13  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
18  * THE SOFTWARE.
19  *
20  */
21 
22 #ifndef UTILIB_LOG_HPP_
23 #define UTILIB_LOG_HPP_
24 
25 #include <time.h>
26 #include <iostream>
27 #include <memory>
28 #include <sstream>
29 #include <string>
30 
31 namespace UtilLib {
127 enum LogLevel {
128  logERROR, // !< logERROR
129  logWARNING, // !< logWARNING
130  logINFO, // !< logINFO
131  logDEBUG, // !< logDEBUG
132  logDEBUG1, // !< logDEBUG1
133  logDEBUG2, // !< logDEBUG2
134  logDEBUG3, // !< logDEBUG3
135  logDEBUG4 // !< logDEBUG4
136 };
137 
141 class Log {
142  public:
146  Log() = default;
150  Log(const Log&) = delete;
155  Log& operator =(const Log&) = delete;
156 
160  virtual ~Log();
161 
167  std::ostringstream& writeReport(LogLevel level = logINFO);
168 
173  static std::shared_ptr<std::ostream> getStream();
174 
179  static void setStream(std::shared_ptr<std::ostream> pStream);
180 
185  static LogLevel getReportingLevel();
186 
191  static void setReportingLevel(LogLevel level);
192 
193  private:
198  static void writeOutput(const std::string& msg);
199 
204  static LogLevel reportingLevel_;
205 
209  static std::shared_ptr<std::ostream> pStream_;
213  std::ostringstream buffer_;
214 };
215 } /* end namespace */
216 
222 #define LOG(level) \
223  if (level > UtilLib::Log::getReportingLevel() || !UtilLib::Log::getStream()) ; \
224  else UtilLib::Log().writeReport(level)
225 
226 
227 
228 #endif /* UTILIB_LOG_HPP_ */
static LogLevel getReportingLevel()
Definition: Log.cpp:129
class for logging reports. The usage of this log class is described on page The Log utilities provide...
Definition: Log.hpp:141
Log()=default
Log & operator=(const Log &)=delete
static void setStream(std::shared_ptr< std::ostream > pStream)
Definition: Log.cpp:91
static void setReportingLevel(LogLevel level)
Definition: Log.cpp:122
std::ostringstream & writeReport(LogLevel level=logINFO)
Definition: Log.cpp:105
virtual ~Log()
Definition: Log.cpp:133
static std::shared_ptr< std::ostream > getStream()
Definition: Log.cpp:87