2019-06-04 05:09:16 +08:00
|
|
|
// Copyright(c) 2015-present, Gabi Melman & spdlog contributors.
|
2019-05-12 01:06:17 +08:00
|
|
|
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
|
2019-05-12 06:12:46 +08:00
|
|
|
|
2023-09-29 05:05:17 +08:00
|
|
|
#include "spdlog/common.h"
|
|
|
|
#include "spdlog/pattern_formatter.h"
|
|
|
|
#include "spdlog/spdlog.h"
|
2023-09-25 01:26:32 +08:00
|
|
|
|
|
|
|
namespace spdlog {
|
|
|
|
|
2023-09-25 07:35:55 +08:00
|
|
|
void initialize_logger(std::shared_ptr<logger> logger) {
|
2023-09-25 01:26:32 +08:00
|
|
|
details::registry::instance().initialize_logger(std::move(logger));
|
|
|
|
}
|
|
|
|
|
2023-09-25 21:05:07 +08:00
|
|
|
std::shared_ptr<logger> get(const std::string &name) {
|
|
|
|
return details::registry::instance().get(name);
|
|
|
|
}
|
2023-09-25 01:26:32 +08:00
|
|
|
|
2023-09-25 07:35:55 +08:00
|
|
|
void set_formatter(std::unique_ptr<spdlog::formatter> formatter) {
|
2023-09-25 01:26:32 +08:00
|
|
|
details::registry::instance().set_formatter(std::move(formatter));
|
|
|
|
}
|
|
|
|
|
2023-09-25 07:35:55 +08:00
|
|
|
void set_pattern(std::string pattern, pattern_time_type time_type) {
|
2023-09-25 21:05:07 +08:00
|
|
|
set_formatter(
|
|
|
|
std::unique_ptr<spdlog::formatter>(new pattern_formatter(std::move(pattern), time_type)));
|
2023-09-25 01:26:32 +08:00
|
|
|
}
|
|
|
|
|
2023-09-25 07:35:55 +08:00
|
|
|
level get_level() { return default_logger_raw()->log_level(); }
|
2023-09-25 01:26:32 +08:00
|
|
|
|
2023-09-25 07:35:55 +08:00
|
|
|
bool should_log(level level) { return default_logger_raw()->should_log(level); }
|
2023-09-25 01:26:32 +08:00
|
|
|
|
2023-09-25 07:35:55 +08:00
|
|
|
void set_level(level level) { details::registry::instance().set_level(level); }
|
2023-09-25 01:26:32 +08:00
|
|
|
|
2023-09-25 07:35:55 +08:00
|
|
|
void flush_on(level level) { details::registry::instance().flush_on(level); }
|
2023-09-25 01:26:32 +08:00
|
|
|
|
2023-09-25 07:35:55 +08:00
|
|
|
void set_error_handler(void (*handler)(const std::string &msg)) {
|
2023-09-25 01:26:32 +08:00
|
|
|
details::registry::instance().set_error_handler(handler);
|
|
|
|
}
|
|
|
|
|
2023-09-25 07:35:55 +08:00
|
|
|
void register_logger(std::shared_ptr<logger> logger) {
|
2023-09-25 01:26:32 +08:00
|
|
|
details::registry::instance().register_logger(std::move(logger));
|
|
|
|
}
|
|
|
|
|
2023-09-25 07:35:55 +08:00
|
|
|
void apply_all(const std::function<void(std::shared_ptr<logger>)> &fun) {
|
2023-09-25 01:26:32 +08:00
|
|
|
details::registry::instance().apply_all(fun);
|
|
|
|
}
|
|
|
|
|
2023-09-25 07:35:55 +08:00
|
|
|
void drop(const std::string &name) { details::registry::instance().drop(name); }
|
2023-09-25 01:26:32 +08:00
|
|
|
|
2023-09-25 07:35:55 +08:00
|
|
|
void drop_all() { details::registry::instance().drop_all(); }
|
2023-09-25 01:26:32 +08:00
|
|
|
|
2023-09-25 07:35:55 +08:00
|
|
|
void shutdown() { details::registry::instance().shutdown(); }
|
2023-09-25 01:26:32 +08:00
|
|
|
|
2023-09-25 07:35:55 +08:00
|
|
|
void set_automatic_registration(bool automatic_registration) {
|
2023-09-25 01:26:32 +08:00
|
|
|
details::registry::instance().set_automatic_registration(automatic_registration);
|
|
|
|
}
|
|
|
|
|
2023-09-25 21:05:07 +08:00
|
|
|
std::shared_ptr<spdlog::logger> default_logger() {
|
|
|
|
return details::registry::instance().default_logger();
|
|
|
|
}
|
2023-09-25 01:26:32 +08:00
|
|
|
|
2023-09-25 07:35:55 +08:00
|
|
|
spdlog::logger *default_logger_raw() { return details::registry::instance().get_default_raw(); }
|
2023-09-25 01:26:32 +08:00
|
|
|
|
2023-09-25 07:35:55 +08:00
|
|
|
void set_default_logger(std::shared_ptr<spdlog::logger> default_logger) {
|
2023-09-25 01:26:32 +08:00
|
|
|
details::registry::instance().set_default_logger(std::move(default_logger));
|
|
|
|
}
|
|
|
|
|
2023-09-25 07:35:55 +08:00
|
|
|
void apply_logger_env_levels(std::shared_ptr<logger> logger) {
|
2023-09-25 01:26:32 +08:00
|
|
|
details::registry::instance().apply_logger_env_levels(std::move(logger));
|
|
|
|
}
|
|
|
|
|
2023-09-25 21:40:05 +08:00
|
|
|
} // namespace spdlog
|