OpenTREP Logo  0.07.7
C++ Open Travel Request Parsing Library
Logger.hpp
Go to the documentation of this file.
1 #ifndef __OPENTREP_SVC_LOGGER_HPP
2 #define __OPENTREP_SVC_LOGGER_HPP
3 
4 // //////////////////////////////////////////////////////////////////////
5 // Import section
6 // //////////////////////////////////////////////////////////////////////
7 // STL
8 #include <cassert>
9 #include <sstream>
10 #include <string>
11 // Boost Date-Time
12 #include <boost/date_time.hpp>
13 // OpenTREP
15 
16 // /////////////// LOG MACROS /////////////////
17 #define OPENTREP_LOG_CORE(iLevel, iToBeLogged) \
18  { std::ostringstream ostr; ostr << iToBeLogged; \
19  OPENTREP::Logger::instance().log (iLevel, __LINE__, __FILE__, ostr.str()); }
20 
21 #define OPENTREP_LOG_CRITICAL(iToBeLogged) \
22  OPENTREP_LOG_CORE (OPENTREP::LOG::CRITICAL, iToBeLogged)
23 
24 #define OPENTREP_LOG_ERROR(iToBeLogged) \
25  OPENTREP_LOG_CORE (OPENTREP::LOG::ERROR, iToBeLogged)
26 
27 #define OPENTREP_LOG_NOTIFICATION(iToBeLogged) \
28  OPENTREP_LOG_CORE (OPENTREP::LOG::NOTIFICATION, iToBeLogged)
29 
30 #define OPENTREP_LOG_WARNING(iToBeLogged) \
31  OPENTREP_LOG_CORE (OPENTREP::LOG::WARNING, iToBeLogged)
32 
33 #define OPENTREP_LOG_DEBUG(iToBeLogged) \
34  OPENTREP_LOG_CORE (OPENTREP::LOG::DEBUG, iToBeLogged)
35 
36 #define OPENTREP_LOG_VERBOSE(iToBeLogged) \
37  OPENTREP_LOG_CORE (OPENTREP::LOG::VERBOSE, iToBeLogged)
38 // /////////// (END OF) LOG MACROS /////////////
39 
40 
41 namespace OPENTREP {
42 
49  class Logger {
50  // Friend classes
51  friend class FacSupervisor;
52  public:
53 
57  template <typename T>
58  void log (const LOG::EN_LogLevel iLevel, const int iLineNumber,
59  const std::string& iFileName, const T& iToBeLogged) {
60  if (iLevel <= _level) {
61  assert (_logStream != NULL);
62 
63  // Get the current time in UTC Timezone
64  boost::posix_time::ptime lTimeUTC =
65  boost::posix_time::second_clock::universal_time();
66 
67  // Add some context and write down the log element
68  *_logStream << "[" << lTimeUTC << "][" << iFileName << "#"
69  << iLineNumber << "]:" << iToBeLogged << std::endl;
70  }
71  }
72 
77 
81  std::ostream& getLogStream();
82 
86  void setLogParameters (const LOG::EN_LogLevel iLogLevel,
87  std::ostream& ioLogStream);
88 
92  static Logger& instance();
93 
94  private:
99  Logger ();
100  Logger (const Logger&);
101  Logger (const LOG::EN_LogLevel iLevel, std::ostream& ioLogStream);
102 
106  ~Logger ();
107 
108  private:
112  LOG::EN_LogLevel _level;
113 
117  std::ostream* _logStream;
118 
122  static Logger* _instance;
123  };
124 
125 }
126 #endif // __OPENTREP_SVC_LOGGER_HPP
OPENTREP::Logger::getLogStream
std::ostream & getLogStream()
Definition: Logger.cpp:41
OPENTREP::Logger::log
void log(const LOG::EN_LogLevel iLevel, const int iLineNumber, const std::string &iFileName, const T &iToBeLogged)
Definition: Logger.hpp:58
OPENTREP::FacSupervisor
Definition: FacSupervisor.hpp:21
OPENTREP::Logger::instance
static Logger & instance()
Definition: Logger.cpp:54
OPENTREP
Definition: BasChronometer.cpp:10
OPENTREP::Logger
Definition: Logger.hpp:49
OPENTREP::Logger::setLogParameters
void setLogParameters(const LOG::EN_LogLevel iLogLevel, std::ostream &ioLogStream)
Definition: Logger.cpp:47
OPENTREP_Types.hpp
OPENTREP::LOG::EN_LogLevel
EN_LogLevel
Definition: OPENTREP_log.hpp:15
OPENTREP::Logger::getLogLevel
LOG::EN_LogLevel getLogLevel()
Definition: Logger.cpp:36