OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
debuglog.hpp
Go to the documentation of this file.
1 #ifndef DEBUG_LOG_H
2 #define DEBUG_LOG_H
3 
4 #include <mutex>
5 #include <iostream>
6 
7 namespace Debug
8 {
9  enum Level
10  {
11  NoLevel = 0,
12  Error = 1,
13  Warning = 2,
14  Info = 3,
15  Verbose = 4,
17  };
18 
19  extern Level CurrentDebugLevel;
20 }
21 
22 class Log
23 {
24  static std::mutex sLock;
25 
26  std::unique_lock<std::mutex> mLock;
27 public:
28  // Locks a global lock while the object is alive
29  Log(Debug::Level level) :
30  mLock(sLock),
31  mLevel(level)
32  {
34  std::cout << static_cast<unsigned char>(mLevel);
35  }
36 
37  // Perfect forwarding wrappers to give the chain of objects to cout
38  template<typename T>
39  Log& operator<<(T&& rhs)
40  {
42  std::cout << std::forward<T>(rhs);
43 
44  return *this;
45  }
46 
47  ~Log()
48  {
50  std::cout << std::endl;
51  }
52 
53 private:
55 };
56 
57 #endif
Definition: debuglog.hpp:12
Definition: debuglog.hpp:13
std::unique_lock< std::mutex > mLock
Definition: debuglog.hpp:26
Definition: debuglog.hpp:22
Log(Debug::Level level)
Definition: debuglog.hpp:29
Level
Definition: debuglog.hpp:9
Definition: debuglog.hpp:14
Debug::Level mLevel
Definition: debuglog.hpp:54
Definition: debuglog.hpp:16
Level CurrentDebugLevel
Definition: debuglog.cpp:5
Definition: debuglog.hpp:15
Log & operator<<(T &&rhs)
Definition: debuglog.hpp:39
Definition: debuglog.hpp:11
static std::mutex sLock
Definition: debuglog.hpp:24
~Log()
Definition: debuglog.hpp:47