My Project
logger.h
1 #ifndef LOGGER_H_INCLUDED_
2 #define LOGGER_H_INCLUDED_
3 
4 #include "kblib/stringops.h"
5 
6 namespace detail {
7 void log(std::string_view str);
8 } // namespace detail
9 
10 enum class log_level {
11  silent = 0,
12  err = 1,
13  warn = 2,
14  notice = 3,
15  info = 4,
16  debug = 5,
17 };
18 
19 void set_log_level(log_level);
20 log_level get_log_level();
21 
22 void set_log_output(std::ostream&);
23 
24 template <typename... Strings>
25 void log_debug(Strings&&... strings) {
26  if (get_log_level() >= log_level::debug) {
27  detail::log(kblib::concat("DEBUG: ", strings...));
28  }
29 }
30 
31 template <typename... Strings>
32 void log_info(Strings&&... strings) {
33  if (get_log_level() >= log_level::info) {
34  detail::log(kblib::concat("INFO: ", strings...));
35  }
36 }
37 
38 template <typename... Strings>
39 void log_notice(Strings&&... strings) {
40  if (get_log_level() >= log_level::notice) {
41  detail::log(kblib::concat("NOTICE: ", strings...));
42  }
43 }
44 
45 template <typename... Strings>
46 void log_warn(Strings&&... strings) {
47  if (get_log_level() >= log_level::warn) {
48  detail::log(kblib::concat("WARN: ", strings...));
49  }
50 }
51 
52 template <typename... Strings>
53 void log_err(Strings&&... strings) {
54  if (get_log_level() >= log_level::err) {
55  detail::log(kblib::concat("ERROR: ", strings...));
56  }
57 }
58 
59 #endif // LOGGER_H_INCLUDED_
Definition: logger.cpp:14