|
|
@ -25,7 +25,7 @@
|
|
|
|
namespace spdlog {
|
|
|
|
namespace spdlog {
|
|
|
|
namespace details {
|
|
|
|
namespace details {
|
|
|
|
|
|
|
|
|
|
|
|
SPDLOG_INLINE registry::registry()
|
|
|
|
registry::registry()
|
|
|
|
: formatter_(new pattern_formatter())
|
|
|
|
: formatter_(new pattern_formatter())
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
@ -44,15 +44,15 @@ SPDLOG_INLINE registry::registry()
|
|
|
|
#endif // SPDLOG_DISABLE_DEFAULT_LOGGER
|
|
|
|
#endif // SPDLOG_DISABLE_DEFAULT_LOGGER
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SPDLOG_INLINE registry::~registry() = default;
|
|
|
|
registry::~registry() = default;
|
|
|
|
|
|
|
|
|
|
|
|
SPDLOG_INLINE void registry::register_logger(std::shared_ptr<logger> new_logger)
|
|
|
|
void registry::register_logger(std::shared_ptr<logger> new_logger)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
|
|
|
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
|
|
|
register_logger_(std::move(new_logger));
|
|
|
|
register_logger_(std::move(new_logger));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SPDLOG_INLINE void registry::initialize_logger(std::shared_ptr<logger> new_logger)
|
|
|
|
void registry::initialize_logger(std::shared_ptr<logger> new_logger)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
|
|
|
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
|
|
|
new_logger->set_formatter(formatter_->clone());
|
|
|
|
new_logger->set_formatter(formatter_->clone());
|
|
|
@ -71,14 +71,14 @@ SPDLOG_INLINE void registry::initialize_logger(std::shared_ptr<logger> new_logge
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SPDLOG_INLINE std::shared_ptr<logger> registry::get(const std::string &logger_name)
|
|
|
|
std::shared_ptr<logger> registry::get(const std::string &logger_name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
|
|
|
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
|
|
|
auto found = loggers_.find(logger_name);
|
|
|
|
auto found = loggers_.find(logger_name);
|
|
|
|
return found == loggers_.end() ? nullptr : found->second;
|
|
|
|
return found == loggers_.end() ? nullptr : found->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SPDLOG_INLINE std::shared_ptr<logger> registry::default_logger()
|
|
|
|
std::shared_ptr<logger> registry::default_logger()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
|
|
|
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
|
|
|
return default_logger_;
|
|
|
|
return default_logger_;
|
|
|
@ -88,14 +88,14 @@ SPDLOG_INLINE std::shared_ptr<logger> registry::default_logger()
|
|
|
|
// To be used directly by the spdlog default api (e.g. spdlog::info)
|
|
|
|
// To be used directly by the spdlog default api (e.g. spdlog::info)
|
|
|
|
// This make the default API faster, but cannot be used concurrently with set_default_logger().
|
|
|
|
// This make the default API faster, but cannot be used concurrently with set_default_logger().
|
|
|
|
// e.g do not call set_default_logger() from one thread while calling spdlog::info() from another.
|
|
|
|
// e.g do not call set_default_logger() from one thread while calling spdlog::info() from another.
|
|
|
|
SPDLOG_INLINE logger *registry::get_default_raw()
|
|
|
|
logger *registry::get_default_raw()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return default_logger_.get();
|
|
|
|
return default_logger_.get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// set default logger.
|
|
|
|
// set default logger.
|
|
|
|
// default logger is stored in default_logger_ (for faster retrieval) and in the loggers_ map.
|
|
|
|
// default logger is stored in default_logger_ (for faster retrieval) and in the loggers_ map.
|
|
|
|
SPDLOG_INLINE void registry::set_default_logger(std::shared_ptr<logger> new_default_logger)
|
|
|
|
void registry::set_default_logger(std::shared_ptr<logger> new_default_logger)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
|
|
|
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
|
|
|
// remove previous default logger from the map
|
|
|
|
// remove previous default logger from the map
|
|
|
@ -110,20 +110,20 @@ SPDLOG_INLINE void registry::set_default_logger(std::shared_ptr<logger> new_defa
|
|
|
|
default_logger_ = std::move(new_default_logger);
|
|
|
|
default_logger_ = std::move(new_default_logger);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SPDLOG_INLINE void registry::set_tp(std::shared_ptr<thread_pool> tp)
|
|
|
|
void registry::set_tp(std::shared_ptr<thread_pool> tp)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::lock_guard<std::recursive_mutex> lock(tp_mutex_);
|
|
|
|
std::lock_guard<std::recursive_mutex> lock(tp_mutex_);
|
|
|
|
tp_ = std::move(tp);
|
|
|
|
tp_ = std::move(tp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SPDLOG_INLINE std::shared_ptr<thread_pool> registry::get_tp()
|
|
|
|
std::shared_ptr<thread_pool> registry::get_tp()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::lock_guard<std::recursive_mutex> lock(tp_mutex_);
|
|
|
|
std::lock_guard<std::recursive_mutex> lock(tp_mutex_);
|
|
|
|
return tp_;
|
|
|
|
return tp_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Set global formatter. Each sink in each logger will get a clone of this object
|
|
|
|
// Set global formatter. Each sink in each logger will get a clone of this object
|
|
|
|
SPDLOG_INLINE void registry::set_formatter(std::unique_ptr<formatter> formatter)
|
|
|
|
void registry::set_formatter(std::unique_ptr<formatter> formatter)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
|
|
|
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
|
|
|
formatter_ = std::move(formatter);
|
|
|
|
formatter_ = std::move(formatter);
|
|
|
@ -133,7 +133,7 @@ SPDLOG_INLINE void registry::set_formatter(std::unique_ptr<formatter> formatter)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SPDLOG_INLINE void registry::set_level(level::level_enum log_level)
|
|
|
|
void registry::set_level(level::level_enum log_level)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
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_)
|
|
|
@ -143,7 +143,7 @@ SPDLOG_INLINE void registry::set_level(level::level_enum log_level)
|
|
|
|
levels_.set_default(log_level);
|
|
|
|
levels_.set_default(log_level);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SPDLOG_INLINE void registry::flush_on(level::level_enum log_level)
|
|
|
|
void registry::flush_on(level::level_enum log_level)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
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_)
|
|
|
@ -153,14 +153,14 @@ SPDLOG_INLINE void registry::flush_on(level::level_enum log_level)
|
|
|
|
flush_level_ = log_level;
|
|
|
|
flush_level_ = log_level;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SPDLOG_INLINE void registry::flush_every(std::chrono::seconds interval)
|
|
|
|
void registry::flush_every(std::chrono::seconds interval)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(flusher_mutex_);
|
|
|
|
std::lock_guard<std::mutex> lock(flusher_mutex_);
|
|
|
|
auto clbk = [this]() { this->flush_all(); };
|
|
|
|
auto clbk = [this]() { this->flush_all(); };
|
|
|
|
periodic_flusher_ = std::make_unique<periodic_worker>(clbk, interval);
|
|
|
|
periodic_flusher_ = std::make_unique<periodic_worker>(clbk, interval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SPDLOG_INLINE void registry::set_error_handler(void (*handler)(const std::string &msg))
|
|
|
|
void registry::set_error_handler(void (*handler)(const std::string &msg))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
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_)
|
|
|
@ -170,7 +170,7 @@ SPDLOG_INLINE void registry::set_error_handler(void (*handler)(const std::string
|
|
|
|
err_handler_ = handler;
|
|
|
|
err_handler_ = handler;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SPDLOG_INLINE void registry::apply_all(const std::function<void(const std::shared_ptr<logger>)> &fun)
|
|
|
|
void registry::apply_all(const std::function<void(const std::shared_ptr<logger>)> &fun)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
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_)
|
|
|
@ -179,7 +179,7 @@ SPDLOG_INLINE void registry::apply_all(const std::function<void(const std::share
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SPDLOG_INLINE void registry::flush_all()
|
|
|
|
void registry::flush_all()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
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_)
|
|
|
@ -188,7 +188,7 @@ SPDLOG_INLINE void registry::flush_all()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SPDLOG_INLINE void registry::drop(const std::string &logger_name)
|
|
|
|
void registry::drop(const std::string &logger_name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
|
|
|
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
|
|
|
loggers_.erase(logger_name);
|
|
|
|
loggers_.erase(logger_name);
|
|
|
@ -198,7 +198,7 @@ SPDLOG_INLINE void registry::drop(const std::string &logger_name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SPDLOG_INLINE void registry::drop_all()
|
|
|
|
void registry::drop_all()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
|
|
|
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
|
|
|
loggers_.clear();
|
|
|
|
loggers_.clear();
|
|
|
@ -206,7 +206,7 @@ SPDLOG_INLINE void registry::drop_all()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// clean all resources and threads started by the registry
|
|
|
|
// clean all resources and threads started by the registry
|
|
|
|
SPDLOG_INLINE void registry::shutdown()
|
|
|
|
void registry::shutdown()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(flusher_mutex_);
|
|
|
|
std::lock_guard<std::mutex> lock(flusher_mutex_);
|
|
|
@ -221,18 +221,18 @@ SPDLOG_INLINE void registry::shutdown()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SPDLOG_INLINE std::recursive_mutex ®istry::tp_mutex()
|
|
|
|
std::recursive_mutex ®istry::tp_mutex()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return tp_mutex_;
|
|
|
|
return tp_mutex_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SPDLOG_INLINE void registry::set_automatic_registration(bool automatic_registration)
|
|
|
|
void registry::set_automatic_registration(bool automatic_registration)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
|
|
|
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
|
|
|
automatic_registration_ = automatic_registration;
|
|
|
|
automatic_registration_ = automatic_registration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SPDLOG_INLINE void registry::update_levels(cfg::log_levels levels)
|
|
|
|
void registry::update_levels(cfg::log_levels levels)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
|
|
|
std::lock_guard<std::mutex> lock(logger_map_mutex_);
|
|
|
|
levels_ = std::move(levels);
|
|
|
|
levels_ = std::move(levels);
|
|
|
@ -243,13 +243,13 @@ SPDLOG_INLINE void registry::update_levels(cfg::log_levels levels)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SPDLOG_INLINE registry ®istry::instance()
|
|
|
|
registry ®istry::instance()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
static registry s_instance;
|
|
|
|
static registry s_instance;
|
|
|
|
return s_instance;
|
|
|
|
return s_instance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SPDLOG_INLINE void registry::throw_if_exists_(const std::string &logger_name)
|
|
|
|
void registry::throw_if_exists_(const std::string &logger_name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (loggers_.find(logger_name) != loggers_.end())
|
|
|
|
if (loggers_.find(logger_name) != loggers_.end())
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -257,7 +257,7 @@ SPDLOG_INLINE void registry::throw_if_exists_(const std::string &logger_name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SPDLOG_INLINE void registry::register_logger_(std::shared_ptr<logger> new_logger)
|
|
|
|
void registry::register_logger_(std::shared_ptr<logger> new_logger)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto logger_name = new_logger->name();
|
|
|
|
auto logger_name = new_logger->name();
|
|
|
|
throw_if_exists_(logger_name);
|
|
|
|
throw_if_exists_(logger_name);
|
|
|
|