use global_logger_raw from spdlog.h

This commit is contained in:
gabime 2024-12-06 14:40:50 +02:00
parent f9e59be886
commit 3e753710f4
2 changed files with 12 additions and 4 deletions

View File

@ -77,20 +77,26 @@ SPDLOG_API std::shared_ptr<logger> global_logger();
// Set the global logger. (for example, to replace the global logger with a custom logger)
SPDLOG_API void set_global_logger(std::shared_ptr<logger> global_logger);
// Return the global logger raw pointer.
// 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_global_logger().
// e.g do not call set_global_logger() from one thread while calling spdlog::info() from another.
SPDLOG_API logger *global_logger_raw() noexcept;
template <typename... Args>
void log(source_loc source, level lvl, format_string_t<Args...> fmt, Args &&...args) {
global_logger()->log(source, lvl, fmt, std::forward<Args>(args)...);
global_logger_raw()->log(source, lvl, fmt, std::forward<Args>(args)...);
}
template <typename... Args>
void log(level lvl, format_string_t<Args...> fmt, Args &&...args) {
global_logger()->log(lvl, fmt, std::forward<Args>(args)...);
global_logger_raw()->log(lvl, fmt, std::forward<Args>(args)...);
}
inline void log(level lvl, std::string_view msg) { global_logger()->log(lvl, msg); }
inline void log(level lvl, std::string_view msg) { global_logger_raw()->log(lvl, msg); }
inline void log(source_loc loc, level lvl, std::string_view msg) { global_logger()->log(loc, lvl, msg); }
inline void log(source_loc loc, level lvl, std::string_view msg) { global_logger_raw()->log(loc, lvl, msg); }
template <typename... Args>
void trace(format_string_t<Args...> fmt, Args &&...args) {

View File

@ -26,6 +26,8 @@ void set_global_logger(std::shared_ptr<logger> global_logger) {
context()->set_logger(std::move(global_logger));
}
logger *global_logger_raw() noexcept { return context_ref()->global_logger_raw(); }
void set_formatter(std::unique_ptr<formatter> formatter) {
global_logger()->set_formatter(std::move(formatter));
}