1 #ifndef __LOGGING_HPP__ 2 #define __LOGGING_HPP__ 6 #define LOGGING_LEVEL_ALL 19 #include <unordered_map> 24 #include <logging_common.hpp> 26 #include <std_out_logger.hpp> 27 #include <file_logger.hpp> 28 #include <full_logger.hpp> 29 #include <logger_factory.hpp> 30 #include <logging_creation.hpp> 47 std::chrono::system_clock::time_point tp = std::chrono::system_clock::now();
48 std::time_t tt = std::chrono::system_clock::to_time_t(tp);
55 std::chrono::duration<double> fractional_seconds =
56 (tp - std::chrono::system_clock::from_time_t(tt)) +
57 std::chrono::seconds(gmt.tm_sec);
59 std::string buffer(
"year/mo/dy hr:mn:sc.xxxxxx");
62 "%04d/%02d/%02d %02d:%02d:%09.6f",
68 fractional_seconds.count()
81 return factory_singleton;
91 const logging_config_t& config = { {
"type",
"std_out"}, {
"color",
""} }
93 static std::unique_ptr<logger> singleton(
get_factory().produce(config));
111 inline void log(
const std::string& message,
const log_level level) {
120 inline void log(
const std::string& message) {
125 extern bool LOGGING_SHOW_TRACE;
126 extern bool LOGGING_SHOW_DEBUG;
127 extern bool LOGGING_SHOW_INFO;
128 extern bool LOGGING_SHOW_WARN;
129 extern bool LOGGING_SHOW_ERR;
137 LOGGING_SHOW_TRACE =
false;
138 LOGGING_SHOW_DEBUG =
false;
139 LOGGING_SHOW_INFO =
false;
140 LOGGING_SHOW_WARN =
false;
141 LOGGING_SHOW_ERR =
true;
148 LOGGING_SHOW_TRACE =
false;
149 LOGGING_SHOW_DEBUG =
false;
150 LOGGING_SHOW_INFO =
false;
151 LOGGING_SHOW_WARN =
false;
152 LOGGING_SHOW_ERR =
false;
160 LOGGING_SHOW_TRACE =
false;
161 LOGGING_SHOW_DEBUG =
false;
162 LOGGING_SHOW_INFO =
true;
163 LOGGING_SHOW_WARN =
false;
164 LOGGING_SHOW_ERR =
true;
173 LOGGING_SHOW_TRACE =
false;
174 LOGGING_SHOW_DEBUG =
false;
175 LOGGING_SHOW_INFO =
true;
176 LOGGING_SHOW_WARN =
true;
177 LOGGING_SHOW_ERR =
true;
184 LOGGING_SHOW_TRACE =
true;
185 LOGGING_SHOW_DEBUG =
true;
186 LOGGING_SHOW_INFO =
true;
187 LOGGING_SHOW_WARN =
true;
188 LOGGING_SHOW_ERR =
true;
197 inline void TRACE(
const std::string& message) {
198 if(!LOGGING_SHOW_TRACE)
return;
205 inline void DEBUG(
const std::string& message) {
206 if(!LOGGING_SHOW_DEBUG)
return;
213 inline void INFO(
const std::string& message) {
214 if(!LOGGING_SHOW_INFO)
return;
221 inline void WARN(
const std::string& message) {
222 if(!LOGGING_SHOW_WARN)
return;
229 inline void ERR(
const std::string& message) {
230 if(!LOGGING_SHOW_ERR)
return;
237 #endif //__LOGGING_HPP__ virtual void log(const std::string &message, const log_level level)
Handle a log entry considerings its level.
Definition: logger.hpp:34
void log(const std::string &message, const log_level level)
Log function wrapper for singleton logger.
Definition: logging.hpp:111
Logger factory class can be used to build loggers.
Definition: logger_factory.hpp:9
Definition: logging.hpp:38
std::string timestamp()
Obtain current timestamp with format: "yy/mm/dd HH:MM:SS.xxxxxx".
Definition: logging.hpp:45
void DEBUG(const std::string &message)
Default debug messages logging function.
Definition: logging.hpp:205
void WARN(const std::string &message)
Default warning messages logging function.
Definition: logging.hpp:221
void ERR(const std::string &message)
Default error messages logging function.
Definition: logging.hpp:229
logger & get_logger(const logging_config_t &config={ {"type", "std_out"}, {"color", ""} })
Obtain a singleton logger through singleton factory.
Definition: logging.hpp:90
void INFO(const std::string &message)
Default info messages logging function.
Definition: logging.hpp:213
Class providing the base for any logger.
Definition: logger.hpp:8
void makeVerbose2()
Configure logging mode to make it verbose level 2. Verbose level 2 mode means all messages will be sh...
Definition: logging.hpp:183
logger_factory & get_factory()
Obtain a logger factory singleton instance.
Definition: logging.hpp:79
void makeDefault()
Configure logging mode to make it default. Default mode means only info and error messages will be sh...
Definition: logging.hpp:159
void configure(const logging_config_t &config)
Apply given configuration to current logger.
Definition: logging.hpp:102
void makeQuiet()
Configure logging mode to make it quiet. Quiet mode means only errors will be shown.
Definition: logging.hpp:136
void makeVerbose()
Configure logging mode to make it verbose. Verbose mode means only info, warning and error messages w...
Definition: logging.hpp:172
void makeSilent()
Configure logging mode to make it silent. Silent mode means nothing will be shown.
Definition: logging.hpp:147
void TRACE(const std::string &message)
Default trace messages logging function.
Definition: logging.hpp:197