StdAir Logo  1.00.3
C++ Standard Airline IT Object Library
Logger.hpp
Go to the documentation of this file.
1 #ifndef __STDAIR_SVC_LOGGER_HPP
2 #define __STDAIR_SVC_LOGGER_HPP
3 
4 // //////////////////////////////////////////////////////////////////////
5 // Import section
6 // //////////////////////////////////////////////////////////////////////
7 // STL
8 #include <cassert>
9 #include <sstream>
10 #include <string>
11 // StdAir
12 #include <stdair/stdair_log.hpp>
14 
15 // /////////////// LOG MACROS /////////////////
16 #define STDAIR_LOG_CORE(iLevel, iToBeLogged) \
17  { std::ostringstream ostr; ostr << iToBeLogged; \
18  stdair::Logger::instance().log (iLevel, __LINE__, __FILE__, ostr.str()); }
19 
20 #define STDAIR_LOG_CRITICAL(iToBeLogged) \
21  STDAIR_LOG_CORE (stdair::LOG::CRITICAL, iToBeLogged)
22 
23 #define STDAIR_LOG_ERROR(iToBeLogged) \
24  STDAIR_LOG_CORE (stdair::LOG::ERROR, iToBeLogged)
25 
26 #define STDAIR_LOG_NOTIFICATION(iToBeLogged) \
27  STDAIR_LOG_CORE (stdair::LOG::NOTIFICATION, iToBeLogged)
28 
29 #define STDAIR_LOG_WARNING(iToBeLogged) \
30  STDAIR_LOG_CORE (stdair::LOG::WARNING, iToBeLogged)
31 
32 #define STDAIR_LOG_DEBUG(iToBeLogged) \
33  STDAIR_LOG_CORE (stdair::LOG::DEBUG, iToBeLogged)
34 
35 #define STDAIR_LOG_VERBOSE(iToBeLogged) \
36  STDAIR_LOG_CORE (stdair::LOG::VERBOSE, iToBeLogged)
37 // /////////// (END OF) LOG MACROS /////////////
38 
39 
40 namespace stdair {
41 
48  class Logger {
50  friend class FacSupervisor;
51  friend class STDAIR_Service;
52 
53  public:
54 
58  template <typename T>
59  void log (const LOG::EN_LogLevel iLevel, const int iLineNumber,
60  const std::string& iFileName, const T& iToBeLogged) {
61  assert (_logStream != NULL);
62  if (iLevel <= _level) {
63  *_logStream << "[" << LOG::_logLevels[iLevel] << "]" << iFileName << ":"
64  << iLineNumber << ": " << iToBeLogged << std::endl;
65  }
66  }
67 
71  static Logger& instance();
72 
73 
74  private:
75  // /////////////////// Initialisation and finalisation ////////////////
79  bool getStatus() const {
80  return _hasBeenInitialised;
81  }
82 
86  void setLevel (const LOG::EN_LogLevel& iLevel) {
87  _level = iLevel;
88  }
89 
93  void setStream (std::ostream& ioStream) {
94  _logStream = &ioStream;
95  }
96 
100  void setStatus (const bool iStatus) {
101  _hasBeenInitialised = iStatus;
102  }
103 
108  Logger();
112  Logger (const Logger&);
116  ~Logger();
117 
123  static void init (const BasLogParams&);
124 
128  static BasLogParams getLogParams();
129 
133  static void clean();
134 
135 
136  private:
137  // /////////////////// Attributes ////////////////
141  LOG::EN_LogLevel _level;
142 
146  std::ostream* _logStream;
147 
151  bool _hasBeenInitialised;
152  };
153 
154 }
155 #endif // __STDAIR_SVC_LOGGER_HPP
156 
static const std::string _logLevels[LAST_VALUE]
Definition: stdair_log.hpp:28
Handle on the StdAir library context.
void log(const LOG::EN_LogLevel iLevel, const int iLineNumber, const std::string &iFileName, const T &iToBeLogged)
Definition: Logger.hpp:59
static Logger & instance()
Definition: Logger.cpp:48
Interface for the STDAIR Services.