BlueZero (BØ)
Middleware for distributed applications
interface.h
1 #ifndef B0__LOGGER__INTERFACE_H__INCLUDED
2 #define B0__LOGGER__INTERFACE_H__INCLUDED
3 
4 #include <string>
5 
6 #include <boost/format.hpp>
7 
8 namespace b0
9 {
10 
11 namespace logger
12 {
13 
18 {
19 public:
23  enum LogLevel
24  {
26  trace = 0,
28  debug = 10,
30  info = 20,
32  warn = 30,
34  error = 40,
36  fatal = 50
37  };
38 
42  virtual void log(LogLevel level, std::string message) const = 0;
43 
47  template<typename... Arguments>
48  void log(LogLevel level, std::string const &fmt, Arguments&&... args) const
49  {
50  try
51  {
52  boost::format format(fmt);
53  log_helper(level, format, std::forward<Arguments>(args)...);
54  }
55  catch(boost::io::too_many_args &ex)
56  {
57  std::string s = fmt;
58  s += " (error during formatting)";
59  log(level, s);
60  }
61  }
62 
63 protected:
65 
66  virtual void log_helper(LogLevel level, boost::format &format) const;
67 
68  template<class T, class... Args>
69  void log_helper(LogLevel level, boost::format &format, T &&t, Args&&... args) const
70  {
71  return log_helper(level, format % std::forward<T>(t), std::forward<Args>(args)...);
72  }
73 
75 };
76 
77 } // namespace logger
78 
79 } // namespace b0
80 
81 #endif // B0__LOGGER__INTERFACE_H__INCLUDED
The most verbose level.
Definition: interface.h:26
LogLevel
Definition: interface.h:23
The default level, should not cause too much spam on the console.
Definition: interface.h:30
Less verbose than TRACE.
Definition: interface.h:28
Warning level.
Definition: interface.h:32
Error level.
Definition: interface.h:34
Fatal error level, after which the node would usually terminate.
Definition: interface.h:36
void log(LogLevel level, std::string const &fmt, Arguments &&... args) const
Log a message using a format string.
Definition: interface.h:48
virtual void log(LogLevel level, std::string message) const =0
Log a message to the remote logger, with a specified level.
Base class to add logging functionalities to nodes.
Definition: interface.h:17
Definition: node.h:17