Commit 9f841330 authored by Sam Lunt's avatar Sam Lunt

add global flush_on function

parent a2890f27
...@@ -64,6 +64,7 @@ public: ...@@ -64,6 +64,7 @@ public:
new_logger->set_error_handler(_err_handler); new_logger->set_error_handler(_err_handler);
new_logger->set_level(_level); new_logger->set_level(_level);
new_logger->flush_on(_flush_level);
//Add to registry //Add to registry
...@@ -85,6 +86,7 @@ public: ...@@ -85,6 +86,7 @@ public:
new_logger->set_error_handler(_err_handler); new_logger->set_error_handler(_err_handler);
new_logger->set_level(_level); new_logger->set_level(_level);
new_logger->flush_on(_flush_level);
//Add to registry //Add to registry
_loggers[logger_name] = new_logger; _loggers[logger_name] = new_logger;
...@@ -153,6 +155,14 @@ public: ...@@ -153,6 +155,14 @@ public:
_level = log_level; _level = log_level;
} }
void flush_on(level::level_enum log_level)
{
std::lock_guard<Mutex> lock(_mutex);
for (auto& l : _loggers)
l.second->flush_on(log_level);
_flush_level = log_level;
}
void set_error_handler(log_err_handler handler) void set_error_handler(log_err_handler handler)
{ {
for (auto& l : _loggers) for (auto& l : _loggers)
...@@ -197,6 +207,7 @@ private: ...@@ -197,6 +207,7 @@ private:
std::unordered_map <std::string, std::shared_ptr<logger>> _loggers; std::unordered_map <std::string, std::shared_ptr<logger>> _loggers;
formatter_ptr _formatter; formatter_ptr _formatter;
level::level_enum _level = level::info; level::level_enum _level = level::info;
level::level_enum _flush_level = level::off;
log_err_handler _err_handler; log_err_handler _err_handler;
bool _async_mode = false; bool _async_mode = false;
size_t _async_q_size = 0; size_t _async_q_size = 0;
......
...@@ -236,6 +236,11 @@ inline void spdlog::set_level(level::level_enum log_level) ...@@ -236,6 +236,11 @@ inline void spdlog::set_level(level::level_enum log_level)
return details::registry::instance().set_level(log_level); return details::registry::instance().set_level(log_level);
} }
inline void spdlog::flush_on(level::level_enum log_level)
{
return details::registry::instance().flush_on(log_level);
}
inline void spdlog::set_error_handler(log_err_handler handler) inline void spdlog::set_error_handler(log_err_handler handler)
{ {
return details::registry::instance().set_error_handler(handler); return details::registry::instance().set_error_handler(handler);
......
...@@ -36,10 +36,15 @@ void set_pattern(const std::string& format_string); ...@@ -36,10 +36,15 @@ void set_pattern(const std::string& format_string);
void set_formatter(formatter_ptr f); void set_formatter(formatter_ptr f);
// //
// Set global logging level for // Set global logging level
// //
void set_level(level::level_enum log_level); void set_level(level::level_enum log_level);
//
// Set global flush level
//
void flush_on(level::level_enum log_level);
// //
// Set global error handler // Set global error handler
// //
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment