mirror of
https://github.com/gabime/spdlog.git
synced 2024-12-26 10:31:34 +08:00
Use std::function for the global error handler
This commit is contained in:
parent
7a7611e977
commit
7fa751d36e
@ -195,14 +195,14 @@ SPDLOG_INLINE void registry::flush_every(std::chrono::seconds interval)
|
|||||||
periodic_flusher_ = details::make_unique<periodic_worker>(clbk, interval);
|
periodic_flusher_ = details::make_unique<periodic_worker>(clbk, interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
SPDLOG_INLINE void registry::set_error_handler(void (*handler)(const std::string &msg))
|
SPDLOG_INLINE void registry::set_error_handler(err_handler handler)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
||||||
for (auto &l : loggers_)
|
for (auto &l : loggers_)
|
||||||
{
|
{
|
||||||
l.second->set_error_handler(handler);
|
l.second->set_error_handler(handler);
|
||||||
}
|
}
|
||||||
err_handler_ = handler;
|
err_handler_ = std::move(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
SPDLOG_INLINE void registry::apply_all(const std::function<void(const std::shared_ptr<logger>)> &fun)
|
SPDLOG_INLINE void registry::apply_all(const std::function<void(const std::shared_ptr<logger>)> &fun)
|
||||||
|
@ -63,7 +63,7 @@ public:
|
|||||||
|
|
||||||
void flush_every(std::chrono::seconds interval);
|
void flush_every(std::chrono::seconds interval);
|
||||||
|
|
||||||
void set_error_handler(void (*handler)(const std::string &msg));
|
void set_error_handler(err_handler handler);
|
||||||
|
|
||||||
void apply_all(const std::function<void(const std::shared_ptr<logger>)> &fun);
|
void apply_all(const std::function<void(const std::shared_ptr<logger>)> &fun);
|
||||||
|
|
||||||
@ -99,7 +99,7 @@ private:
|
|||||||
std::unique_ptr<formatter> formatter_;
|
std::unique_ptr<formatter> formatter_;
|
||||||
spdlog::level::level_enum global_log_level_ = level::info;
|
spdlog::level::level_enum global_log_level_ = level::info;
|
||||||
level::level_enum flush_level_ = level::off;
|
level::level_enum flush_level_ = level::off;
|
||||||
void (*err_handler_)(const std::string &msg) = nullptr;
|
err_handler err_handler_;
|
||||||
std::shared_ptr<thread_pool> tp_;
|
std::shared_ptr<thread_pool> tp_;
|
||||||
std::unique_ptr<periodic_worker> periodic_flusher_;
|
std::unique_ptr<periodic_worker> periodic_flusher_;
|
||||||
std::shared_ptr<logger> default_logger_;
|
std::shared_ptr<logger> default_logger_;
|
||||||
|
Loading…
Reference in New Issue
Block a user