add global flush_on function

This commit is contained in:
Sam Lunt 2018-01-03 09:19:56 -06:00
parent a2890f2778
commit 9f8413308a
3 changed files with 22 additions and 1 deletions

View File

@ -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:
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:
_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:
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;

View File

@ -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);

View File

@ -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
// //