EEROS  0.4.1.0
API for the EEROS Real-Time Robotics Framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Logger.hpp
Go to the documentation of this file.
1 #ifndef ORG_EEROS_LOGGER_LOGGER_HPP_
2 #define ORG_EEROS_LOGGER_LOGGER_HPP_
3 
5 
6 namespace eeros {
7  namespace logger {
8 
9  template < typename TWriter >
10  class Logger {
11  public:
12  Logger(unsigned category = 0) : w(defaultWriter), category(category) { }
13 
14  void set(TWriter* writer) { w = writer; }
15  void set(TWriter& writer) { w = &writer; }
16  TWriter* get() { return w; }
17 
18  LogEntry<TWriter> fatal() { return LogEntry<TWriter>(w, 0, category); }
19  LogEntry<TWriter> error() { return LogEntry<TWriter>(w, 1, category); }
20  LogEntry<TWriter> warn() { return LogEntry<TWriter>(w, 2, category); }
21  LogEntry<TWriter> info() { return LogEntry<TWriter>(w, 3, category); }
22  LogEntry<TWriter> trace() { return LogEntry<TWriter>(w, 4, category); }
23 
24  LogEntry<TWriter> operator <<(unsigned level) { return LogEntry<TWriter>(w, level, category); }
25 
26 
27  static void setDefaultWriter(TWriter* writer) { defaultWriter = writer; }
28  private:
29  TWriter* w;
30  unsigned category;
31 
32  static TWriter* defaultWriter;
33  };
34 
35  template < typename TWriter >
36  TWriter* Logger<TWriter>::defaultWriter = nullptr;
37  }
38 }
39 
40 #endif /* ORG_EEROS_LOGGER_LOGGER_HPP_ */
Definition: Logger.hpp:10
Logger(unsigned category=0)
Definition: Logger.hpp:12
LogEntry< TWriter > error()
Definition: Logger.hpp:19
LogEntry< TWriter > trace()
Definition: Logger.hpp:22
Definition: LogEntry.hpp:7
static void setDefaultWriter(TWriter *writer)
Definition: Logger.hpp:27
LogEntry< TWriter > operator<<(unsigned level)
Definition: Logger.hpp:24
LogEntry< TWriter > warn()
Definition: Logger.hpp:20
void set(TWriter *writer)
Definition: Logger.hpp:14
LogEntry< TWriter > info()
Definition: Logger.hpp:21
void set(TWriter &writer)
Definition: Logger.hpp:15
LogEntry< TWriter > fatal()
Definition: Logger.hpp:18