11 #include "../async_logger.h" 12 #include "../details/async_log_helper.h" 20 inline spdlog::async_logger::async_logger(
const std::string &logger_name,
const It &begin,
const It &end,
size_t queue_size,
21 const async_overflow_policy overflow_policy,
const std::function<
void()> &worker_warmup_cb,
22 const std::chrono::milliseconds &flush_interval_ms,
const std::function<
void()> &worker_teardown_cb)
23 : logger(logger_name, begin, end)
24 , _async_log_helper(new details::async_log_helper(logger_name, _formatter, _sinks, queue_size, _err_handler, overflow_policy,
25 worker_warmup_cb, flush_interval_ms, worker_teardown_cb))
29 inline spdlog::async_logger::async_logger(
const std::string &logger_name, sinks_init_list sinks_list,
size_t queue_size,
30 const async_overflow_policy overflow_policy,
const std::function<
void()> &worker_warmup_cb,
31 const std::chrono::milliseconds &flush_interval_ms,
const std::function<
void()> &worker_teardown_cb)
32 : async_logger(logger_name, sinks_list.begin(), sinks_list.end(), queue_size, overflow_policy, worker_warmup_cb, flush_interval_ms,
37 inline spdlog::async_logger::async_logger(
const std::string &logger_name, sink_ptr single_sink,
size_t queue_size,
38 const async_overflow_policy overflow_policy,
const std::function<
void()> &worker_warmup_cb,
39 const std::chrono::milliseconds &flush_interval_ms,
const std::function<
void()> &worker_teardown_cb)
41 logger_name, {std::move(single_sink)}, queue_size, overflow_policy, worker_warmup_cb, flush_interval_ms, worker_teardown_cb)
45 inline void spdlog::async_logger::flush()
47 _async_log_helper->flush();
51 inline void spdlog::async_logger::set_error_handler(spdlog::log_err_handler err_handler)
53 _err_handler = err_handler;
54 _async_log_helper->set_error_handler(err_handler);
56 inline spdlog::log_err_handler spdlog::async_logger::error_handler()
61 inline void spdlog::async_logger::_set_formatter(spdlog::formatter_ptr msg_formatter)
63 _formatter = msg_formatter;
64 _async_log_helper->set_formatter(_formatter);
67 inline void spdlog::async_logger::_set_pattern(
const std::string &pattern, pattern_time_type pattern_time)
69 _formatter = std::make_shared<pattern_formatter>(pattern, pattern_time);
70 _async_log_helper->set_formatter(_formatter);
73 inline void spdlog::async_logger::_sink_it(details::log_msg &msg)
77 #if defined(SPDLOG_ENABLE_MESSAGE_COUNTER) 78 _incr_msg_counter(msg);
80 _async_log_helper->log(msg);
81 if (_should_flush_on(msg))
83 _async_log_helper->flush();
86 catch (
const std::exception &ex)
88 _err_handler(ex.what());
92 _err_handler(
"Unknown exception in logger " + _name);