spdlog/src/spdlog.cpp

106 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-25 01:26:32 +08:00
#include <spdlog/spdlog.h>
#include <spdlog/common.h>
#include <spdlog/pattern_formatter.h>
namespace spdlog {
void initialize_logger(std::shared_ptr<logger> logger)
{
details::registry::instance().initialize_logger(std::move(logger));
}
2023-09-25 01:43:14 +08:00
std::shared_ptr<logger> get(const std::string &name)
2023-09-25 01:26:32 +08:00
{
return details::registry::instance().get(name);
}
2023-09-25 01:43:14 +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 01:43:14 +08:00
void set_pattern(std::string pattern, pattern_time_type time_type)
2023-09-25 01:26:32 +08:00
{
set_formatter(std::unique_ptr<spdlog::formatter>(new pattern_formatter(std::move(pattern), time_type)));
}
2023-09-25 01:43:14 +08:00
level get_level()
2023-09-25 01:26:32 +08:00
{
return default_logger_raw()->log_level();
}
2023-09-25 01:43:14 +08:00
bool should_log(level level)
2023-09-25 01:26:32 +08:00
{
return default_logger_raw()->should_log(level);
}
2023-09-25 01:43:14 +08:00
void set_level(level level)
2023-09-25 01:26:32 +08:00
{
details::registry::instance().set_level(level);
}
2023-09-25 01:43:14 +08:00
void flush_on(level level)
2023-09-25 01:26:32 +08:00
{
details::registry::instance().flush_on(level);
}
2023-09-25 01:43:14 +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 01:43:14 +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 01:43:14 +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 01:43:14 +08:00
void drop(const std::string &name)
2023-09-25 01:26:32 +08:00
{
details::registry::instance().drop(name);
}
2023-09-25 01:43:14 +08:00
void drop_all()
2023-09-25 01:26:32 +08:00
{
details::registry::instance().drop_all();
}
2023-09-25 01:43:14 +08:00
void shutdown()
2023-09-25 01:26:32 +08:00
{
details::registry::instance().shutdown();
}
2023-09-25 01:43:14 +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 01:43:14 +08:00
std::shared_ptr<spdlog::logger> default_logger()
2023-09-25 01:26:32 +08:00
{
return details::registry::instance().default_logger();
}
2023-09-25 01:43:14 +08:00
spdlog::logger *default_logger_raw()
2023-09-25 01:26:32 +08:00
{
return details::registry::instance().get_default_raw();
}
2023-09-25 01:43:14 +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 01:43:14 +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));
}
} // namespace spdlog