wbc
Logger.hpp
Go to the documentation of this file.
1#ifndef WBC_TOOLS_LOGGER_HPP
2#define WBC_TOOLS_LOGGER_HPP
3
4#include <iostream>
5#include <sstream>
6
7/* consider adding boost thread id since we'll want to know whose writting and
8 * won't want to repeat it for every single call */
9
10/* consider adding policy class to allow users to redirect logging to specific
11 * files via the command line
12 */
13
16
17class logger
18{
19public:
20 logger(loglevel_e _loglevel = logERROR) {
21 _buffer << _loglevel << " :"
22 << std::string(
23 _loglevel > logDEBUG
24 ? (_loglevel - logDEBUG) * 4
25 : 1
26 , ' ');
27 }
28
29 template <typename T>
30 logger & operator<<(T const & value)
31 {
32 _buffer << value;
33 return *this;
34 }
35
37 {
38 _buffer << std::endl;
39 // This is atomic according to the POSIX standard
40 // http://www.gnu.org/s/libc/manual/html_node/Streams-and-Threads.html
41 std::cerr << _buffer.str();
42 }
43
44private:
45 std::ostringstream _buffer;
46};
47
48extern loglevel_e loglevel;
49
50#define log(level) \
51if (level > loglevel) ; \
52else logger(level)
53
54#endif // WBC_TOOLS_LOGGER_HPP
loglevel_e
Definition Logger.hpp:15
@ logDEBUG1
Definition Logger.hpp:15
@ logDEBUG
Definition Logger.hpp:15
@ logDEBUG4
Definition Logger.hpp:15
@ logWARNING
Definition Logger.hpp:15
@ logINFO
Definition Logger.hpp:15
@ logDEBUG2
Definition Logger.hpp:15
@ logDEBUG3
Definition Logger.hpp:15
@ logERROR
Definition Logger.hpp:15
loglevel_e loglevel
Definition Scene.cpp:5
logger & operator<<(T const &value)
Definition Logger.hpp:30
logger(loglevel_e _loglevel=logERROR)
Definition Logger.hpp:20
~logger()
Definition Logger.hpp:36