BuildCache
debug_utils.hpp
1 //--------------------------------------------------------------------------------------------------
2 // Copyright (c) 2018 Marcus Geelnard
3 //
4 // This software is provided 'as-is', without any express or implied warranty. In no event will the
5 // authors be held liable for any damages arising from the use of this software.
6 //
7 // Permission is granted to anyone to use this software for any purpose, including commercial
8 // applications, and to alter it and redistribute it freely, subject to the following restrictions:
9 //
10 // 1. The origin of this software must not be misrepresented; you must not claim that you wrote
11 // the original software. If you use this software in a product, an acknowledgment in the
12 // product documentation would be appreciated but is not required.
13 //
14 // 2. Altered source versions must be plainly marked as such, and must not be misrepresented as
15 // being the original software.
16 //
17 // 3. This notice may not be removed or altered from any source distribution.
18 //--------------------------------------------------------------------------------------------------
19 
20 #ifndef BUILDCACHE_DEBUG_UTILS_HPP_
21 #define BUILDCACHE_DEBUG_UTILS_HPP_
22 
23 #include <sstream>
24 #include <string>
25 
26 namespace bcache {
27 namespace debug {
29 enum log_level_t { DEBUG = 1, INFO = 2, ERROR = 3, FATAL = 4, NONE = 5 };
30 
34 void set_log_level(const int level);
35 
39 void set_log_file(const std::string& file);
40 
47 class log {
48 public:
51  log(const log_level_t level);
52 
56  ~log();
57 
58  template <typename T>
59  log& operator<<(const T message) {
60  m_stream << message;
61  return *this;
62  }
63 
64 private:
65  const log_level_t m_level;
66  std::ostringstream m_stream;
67 };
68 } // namespace debug
69 } // namespace bcache
70 
71 #endif // BUILDCACHE_DEBUG_UTILS_HPP_
bcache::debug::log::~log
~log()
Log stream destructor.
Definition: debug_utils.cpp:99
bcache::debug::log_level_t
log_level_t
Recognized debug log levels.
Definition: debug_utils.hpp:29
bcache
The top level namespace.
Definition: compressor.cpp:34
bcache::debug::set_log_level
void set_log_level(const int level)
Set the global log level.
Definition: debug_utils.cpp:83
bcache::debug::set_log_file
void set_log_file(const std::string &file)
Set the global log file.
Definition: debug_utils.cpp:92
bcache::debug::log::log
log(const log_level_t level)
Log stream constructor.
Definition: debug_utils.cpp:96
bcache::config::debug
int32_t debug()
Definition: configuration.cpp:612
bcache::debug::log
A simple log stream object.
Definition: debug_utils.hpp:47