23 #include <unordered_map> 35 std::lock_guard<Mutex> lock(
_mutex);
36 auto logger_name = logger->name();
44 std::lock_guard<Mutex> lock(
_mutex);
45 auto found =
_loggers.find(logger_name);
46 return found ==
_loggers.end() ?
nullptr : found->second;
50 std::shared_ptr<logger>
create(
const std::string& logger_name,
const It& sinks_begin,
const It& sinks_end)
52 std::lock_guard<Mutex> lock(
_mutex);
54 std::shared_ptr<logger> new_logger;
58 new_logger = std::make_shared<logger>(logger_name, sinks_begin, sinks_end);
66 new_logger->set_level(
_level);
75 std::shared_ptr<async_logger>
create_async(
const std::string& logger_name,
size_t queue_size,
const async_overflow_policy overflow_policy,
const std::function<
void()>& worker_warmup_cb,
const std::chrono::milliseconds& flush_interval_ms,
const std::function<
void()>& worker_teardown_cb,
const It& sinks_begin,
const It& sinks_end)
77 std::lock_guard<Mutex> lock(
_mutex);
79 auto new_logger = std::make_shared<async_logger>(logger_name, sinks_begin, sinks_end, queue_size, overflow_policy, worker_warmup_cb, flush_interval_ms, worker_teardown_cb);
87 new_logger->set_level(
_level);
94 void apply_all(std::function<
void(std::shared_ptr<logger>)> fun)
96 std::lock_guard<Mutex> lock(
_mutex);
103 std::lock_guard<Mutex> lock(
_mutex);
109 std::lock_guard<Mutex> lock(
_mutex);
114 return create(logger_name, sinks.begin(), sinks.end());
119 return create(logger_name, { sink });
122 std::shared_ptr<async_logger>
create_async(
const std::string& logger_name,
size_t queue_size,
const async_overflow_policy overflow_policy,
const std::function<
void()>& worker_warmup_cb,
const std::chrono::milliseconds& flush_interval_ms,
const std::function<
void()>& worker_teardown_cb,
sinks_init_list sinks)
124 return create_async(logger_name, queue_size, overflow_policy, worker_warmup_cb, flush_interval_ms, worker_teardown_cb, sinks.begin(), sinks.end());
127 std::shared_ptr<async_logger>
create_async(
const std::string& logger_name,
size_t queue_size,
const async_overflow_policy overflow_policy,
const std::function<
void()>& worker_warmup_cb,
const std::chrono::milliseconds& flush_interval_ms,
const std::function<
void()>& worker_teardown_cb,
sink_ptr sink)
129 return create_async(logger_name, queue_size, overflow_policy, worker_warmup_cb, flush_interval_ms, worker_teardown_cb, { sink });
134 std::lock_guard<Mutex> lock(
_mutex);
142 std::lock_guard<Mutex> lock(
_mutex);
143 _formatter = std::make_shared<pattern_formatter>(pattern);
150 std::lock_guard<Mutex> lock(
_mutex);
152 l.second->set_level(log_level);
159 l.second->set_error_handler(handler);
163 void set_async_mode(
size_t q_size,
const async_overflow_policy overflow_policy,
const std::function<
void()>& worker_warmup_cb,
const std::chrono::milliseconds& flush_interval_ms,
const std::function<
void()>& worker_teardown_cb)
165 std::lock_guard<Mutex> lock(
_mutex);
176 std::lock_guard<Mutex> lock(
_mutex);
194 throw spdlog_ex(
"logger with name '" + logger_name +
"' already exists");
197 std::unordered_map <std::string, std::shared_ptr<logger>>
_loggers;
208 #ifdef SPDLOG_NO_REGISTRY_MUTEX log_err_handler _err_handler
void set_async_mode(size_t q_size, const async_overflow_policy overflow_policy, const std::function< void()> &worker_warmup_cb, const std::chrono::milliseconds &flush_interval_ms, const std::function< void()> &worker_teardown_cb)
void formatter(formatter_ptr f)
std::shared_ptr< spdlog::formatter > formatter_ptr
std::function< void()> _worker_teardown_cb
std::shared_ptr< sinks::sink > sink_ptr
registry_t< std::mutex > registry
std::chrono::milliseconds _flush_interval_ms
registry_t< Mutex > & operator=(const registry_t< Mutex > &)=delete
std::shared_ptr< logger > create(const std::string &logger_name, sink_ptr sink)
std::shared_ptr< async_logger > create_async(const std::string &logger_name, size_t queue_size, const async_overflow_policy overflow_policy, const std::function< void()> &worker_warmup_cb, const std::chrono::milliseconds &flush_interval_ms, const std::function< void()> &worker_teardown_cb, sink_ptr sink)
std::function< void()> _worker_warmup_cb
std::shared_ptr< async_logger > create_async(const std::string &logger_name, size_t queue_size, const async_overflow_policy overflow_policy, const std::function< void()> &worker_warmup_cb, const std::chrono::milliseconds &flush_interval_ms, const std::function< void()> &worker_teardown_cb, sinks_init_list sinks)
void set_error_handler(log_err_handler handler)
void throw_if_exists(const std::string &logger_name)
std::shared_ptr< logger > create(const std::string &logger_name, sinks_init_list sinks)
std::shared_ptr< logger > create(const std::string &logger_name, const It &sinks_begin, const It &sinks_end)
void drop(const std::string &logger_name)
void set_pattern(const std::string &pattern)
void set_level(level::level_enum log_level)
void apply_all(std::function< void(std::shared_ptr< logger >)> fun)
std::initializer_list< sink_ptr > sinks_init_list
static registry_t< Mutex > & instance()
async_overflow_policy _overflow_policy
std::shared_ptr< async_logger > create_async(const std::string &logger_name, size_t queue_size, const async_overflow_policy overflow_policy, const std::function< void()> &worker_warmup_cb, const std::chrono::milliseconds &flush_interval_ms, const std::function< void()> &worker_teardown_cb, const It &sinks_begin, const It &sinks_end)
std::function< void(const std::string &err_msg)> log_err_handler
void register_logger(std::shared_ptr< logger > logger)
std::unordered_map< std::string, std::shared_ptr< logger > > _loggers