OpenTREP Logo  0.6.0
C++ Open Travel Request Parsing Library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 // C
8 #include <assert.h>
9 // STL
10 #include <sstream>
11 #include <string>
12 // OPENTREP
14 
15 // /////////////// LOG MACROS /////////////////
16 #define OPENTREP_LOG_CORE(iLevel, iToBeLogged) \
17  { std::ostringstream ostr; ostr << iToBeLogged; \
18  OPENTREP::Logger::instance().log (iLevel, __LINE__, __FILE__, ostr.str()); }
19 
20 #define OPENTREP_LOG_CRITICAL(iToBeLogged) \
21  OPENTREP_LOG_CORE (OPENTREP::LOG::CRITICAL, iToBeLogged)
22 
23 #define OPENTREP_LOG_ERROR(iToBeLogged) \
24  OPENTREP_LOG_CORE (OPENTREP::LOG::ERROR, iToBeLogged)
25 
26 #define OPENTREP_LOG_NOTIFICATION(iToBeLogged) \
27  OPENTREP_LOG_CORE (OPENTREP::LOG::NOTIFICATION, iToBeLogged)
28 
29 #define OPENTREP_LOG_WARNING(iToBeLogged) \
30  OPENTREP_LOG_CORE (OPENTREP::LOG::WARNING, iToBeLogged)
31 
32 #define OPENTREP_LOG_DEBUG(iToBeLogged) \
33  OPENTREP_LOG_CORE (OPENTREP::LOG::DEBUG, iToBeLogged)
34 
35 #define OPENTREP_LOG_VERBOSE(iToBeLogged) \
36  OPENTREP_LOG_CORE (OPENTREP::LOG::VERBOSE, iToBeLogged)
37 // /////////// (END OF) LOG MACROS /////////////
38 
39 
40 namespace OPENTREP {
41 
45  class Logger {
46  // Friend classes
47  friend class FacSupervisor;
48  public:
49 
51  template <typename T>
52  void log (const LOG::EN_LogLevel iLevel, const int iLineNumber,
53  const std::string& iFileName, const T& iToBeLogged) {
54  if (iLevel <= _level) {
55  assert (_logStream != NULL);
56  *_logStream << iFileName << ":" << iLineNumber
57  << ": " << iToBeLogged << std::endl;
58  }
59  }
60 
63 
65  std::ostream& getLogStream();
66 
68  void setLogParameters (const LOG::EN_LogLevel iLogLevel,
69  std::ostream& ioLogStream);
70 
72  static Logger& instance();
73 
74  private:
77  Logger ();
78  Logger (const Logger&);
79  Logger (const LOG::EN_LogLevel iLevel, std::ostream& ioLogStream);
81  ~Logger ();
82 
83  private:
85  LOG::EN_LogLevel _level;
86 
88  std::ostream* _logStream;
89 
91  static Logger* _instance;
92  };
93 
94 }
95 #endif // __OPENTREP_SVC_LOGGER_HPP
void setLogParameters(const LOG::EN_LogLevel iLogLevel, std::ostream &ioLogStream)
Definition: Logger.cpp:48
void log(const LOG::EN_LogLevel iLevel, const int iLineNumber, const std::string &iFileName, const T &iToBeLogged)
Definition: Logger.hpp:52
std::ostream & getLogStream()
Definition: Logger.cpp:42
LOG::EN_LogLevel getLogLevel()
Definition: Logger.cpp:37
static Logger & instance()
Definition: Logger.cpp:55