DIY 3.0 data-parallel out-of-core C++ library

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Examples

- File List

All Classes Namespaces Functions Typedefs Groups Pages
log.hpp
1 #ifndef DIY_LOG_HPP
2 #define DIY_LOG_HPP
3
4 #ifndef DIY_USE_SPDLOG
5
6 #include <memory>
7 #include "fmt/format.h"
8 #include "fmt/ostream.h"
9
10 namespace diy
11 {
12
13 namespace spd
14 {
15 struct logger
16 {
17 // logger.info(cppformat_string, arg1, arg2, arg3, ...) call style
18 template <typename... Args> void trace(const char*, const Args&...) {}
19 template <typename... Args> void debug(const char*, const Args&...) {}
20 template <typename... Args> void info(const char*, const Args&...) {}
21 template <typename... Args> void warn(const char*, const Args&...) {}
22 template <typename... Args> void error(const char*, const Args&...) {}
23 template <typename... Args> void critical(const char*, const Args&...) {}
24 };
25 }
26
27 inline
28 std::shared_ptr<spd::logger>
29 get_logger()
30 {
31 return std::make_shared<spd::logger>();
32 }
33
34 inline
35 std::shared_ptr<spd::logger>
36 create_logger(std::string)
37 {
38 return std::make_shared<spd::logger>();
39 }
40
41 template<class... Args>
42 std::shared_ptr<spd::logger>
43 set_logger(Args...)
44 {
45 return std::make_shared<spd::logger>();
46 }
47
48 } // diy
49
50 #else // DIY_USE_SPDLOG
51
52 #include <string>
53
54 #include <spdlog/spdlog.h>
55 #include <spdlog/sinks/null_sink.h>
56
57 #include <spdlog/fmt/bundled/format.h>
58 #include <spdlog/fmt/bundled/ostream.h>
59
60 namespace diy
61 {
62
63 namespace spd = ::spdlog;
64
65 inline
66 std::shared_ptr<spd::logger>
67 get_logger()
68 {
69 auto log = spd::get("diy");
70 if (!log)
71 {
72 auto null_sink = std::make_shared<spd::sinks::null_sink_mt> ();
73 log = std::make_shared<spd::logger>("null_logger", null_sink);
74 }
75 return log;
76 }
77
78 inline
79 std::shared_ptr<spd::logger>
80 create_logger(std::string log_level)
81 {
82 auto log = spd::stderr_logger_mt("diy");
83 int lvl;
84 for (lvl = spd::level::trace; lvl < spd::level::off; ++lvl)
85 if (spd::level::level_names[lvl] == log_level)
86 break;
87 log->set_level(static_cast<spd::level::level_enum>(lvl));
88 return log;
89 }
90
91 template<class... Args>
92 std::shared_ptr<spd::logger>
93 set_logger(Args... args)
94 {
95 auto log = std::make_shared<spdlog::logger>("diy", args...);
96 return log;
97 }
98
99 } // diy
100 #endif
101
102
103 #endif // DIY_LOG_HPP
diy::spd::logger
Definition: log.hpp:15