ClockWork DB CoreAPI 1.0.48
Abstract Time Series and Storage/Management Library
Loading...
Searching...
No Matches
logger.hpp
1 #pragma once
2
3#include <tom-util/defines.hpp>
4#include <tom-util/scalar.hpp>
5#include <spdlog/spdlog.h>
6#include <unordered_map>
7#include <memory>
8
9namespace tom
10{
11 class spdlogdog;
12 class logger;
13
15 {
16 public:
17 explicit spdlogdog(std::shared_ptr<spdlog::logger> l) : m_spdlog(l) {}
18
19 template <class... Args>
20 void
21 info(const std::string &fmt, Args... args)
22 {
23 m_spdlog->info(fmt, args...);
24 }
25
26 template <class... Args>
27 void
28 warn(const std::string &fmt, Args... args)
29 {
30 m_spdlog->warn(fmt, args...);
31 }
32
33 template <class... Args>
34 void
35 error(const std::string &fmt, Args... args)
36 {
37 m_spdlog->error(fmt, args...);
38 }
39
40 template <class... Args>
41 void
42 debug(const std::string &fmt, Args... args)
43 {
44 m_spdlog->debug(fmt, args...);
45 }
46
47 template <class... Args>
48 void
49 fatal(const std::string &fmt, Args... args)
50 {
51 m_spdlog->error(fmt, args...);
52 }
53
54 private:
55 std::shared_ptr<spdlog::logger> m_spdlog;
56 };
57
58 class TOM_UTIL_API logger
59 {
60 public:
61 static void
62 configure(const char *path, const char *level, const char *format, const char *type);
63
64 const tom::String &
65 get_name() const { return m_name; }
66
67 static logger &
68 get_logger(const tom::observation &name) { return get_logger(tom::String(name)); }
69
70 static logger &
71 get_logger(const tom::String &name) { return get_logger(name.value().c_str()); }
72
73 static logger &
74 get_logger(const char *name);
75
76 static logger &
77 get_logger();
78
79 void
80 debug(const tom::observation &message) { debug(tom::String(message)); }
81 void
82 debug(const tom::String &message) { debug(message.value().c_str()); }
83 void
84 debug(const char *message);
85
86 template <class... Args>
87 void
88 debug(const std::string &fmt, Args... args)
89 {
90 m_log->debug(fmt, args...);
91 }
92
93 void
94 info(const tom::observation &message) { info(tom::String(message)); }
95 void
96 info(const tom::String &message) { info(message.value().c_str()); }
97 void
98 info(const char *message);
99
100 template <class... Args>
101 void
102 info(const std::string &fmt, Args... args)
103 {
104 m_log->info(fmt, args...);
105 }
106
107 void
108 warn(const tom::observation &message) { warn(tom::String(message)); }
109 void
110 warn(const tom::String &message) { warn(message.value().c_str()); }
111 void
112 warn(const char *message);
113
114 template <class... Args>
115 void
116 warn(const std::string &fmt, Args... args)
117 {
118 m_log->warn(fmt, args...);
119 }
120
121 void
122 error(const tom::observation &message) { error(tom::String(message)); }
123 void
124 error(const tom::String &message) { error(message.value().c_str()); }
125 void
126 error(const char *message);
127
128 template <class... Args>
129 void
130 error(const std::string &fmt, Args... args)
131 {
132 m_log->error(fmt, args...);
133 }
134
135 void
136 fatal(const tom::observation &message) { fatal(tom::String(message)); }
137 void
138 fatal(const tom::String &message) { fatal(message.value().c_str()); }
139 void
140 fatal(const char *message);
141
142 template <class... Args>
143 void
144 fatal(const std::string &fmt, Args... args)
145 {
146 m_log->error(fmt, args...);
147 }
148
149 private:
150 explicit logger(const std::string &name);
151
152 static std::string DEFAULT_LOG;
153 typedef std::unordered_map<std::string, std::shared_ptr<logger>> logger_map_t;
154
155 tom::String m_name;
156 std::shared_ptr<spdlogdog> m_log;
157
158 // child loggers live here
159 static logger_map_t s_logs;
160 };
161
162} // end tom namespace
Definition string.hpp:15
Definition logger.hpp:59
Definition observation.hpp:13
Definition logger.hpp:15