spdlog/src/spdlog.cpp

75 lines
2.4 KiB
C++
Raw Normal View History

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)
2023-09-29 05:20:26 +08:00
#include "spdlog/spdlog.h"
2023-10-01 17:20:48 +08:00
#include <memory>
#include "spdlog/common.h"
2023-10-01 17:20:48 +08:00
#include "spdlog/logger.h"
#include "spdlog/pattern_formatter.h"
2023-10-01 17:20:48 +08:00
#include "spdlog/sinks/stdout_color_sinks.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));
}
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-10-01 23:01:02 +08:00
set_formatter(std::make_unique<spdlog::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);
}
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