diff options
| author | Stefan Boberg <[email protected]> | 2021-09-15 16:17:22 +0200 |
|---|---|---|
| committer | Stefan Boberg <[email protected]> | 2021-09-15 16:17:22 +0200 |
| commit | 2fc15e320c934424bc03601551f34f26a38e40a3 (patch) | |
| tree | afaf187ad71c5111bf928355c10099b938f4846a /zencore/logging.cpp | |
| parent | Changed `std::exception` into `std::runtime_error` since `std::exception` doe... (diff) | |
| download | zen-2fc15e320c934424bc03601551f34f26a38e40a3.tar.xz zen-2fc15e320c934424bc03601551f34f26a38e40a3.zip | |
Tweaked logging to streamline access, and simplified setup code for new loggers
Diffstat (limited to 'zencore/logging.cpp')
| -rw-r--r-- | zencore/logging.cpp | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/zencore/logging.cpp b/zencore/logging.cpp index 00ec845b4..c5c0b6446 100644 --- a/zencore/logging.cpp +++ b/zencore/logging.cpp @@ -6,11 +6,8 @@ namespace zen { -spdlog::logger& -Log() -{ - return *spdlog::default_logger_raw(); -} +// We shadow the underlying spdlog default logger, in order to avoid a bunch of overhead +spdlog::logger* TheDefaultLogger; } // namespace zen @@ -19,20 +16,24 @@ namespace zen::logging { spdlog::logger& Default() { - return *spdlog::default_logger_raw(); + return *TheDefaultLogger; +} + +void +SetDefault(std::shared_ptr<spdlog::logger> NewDefaultLogger) +{ + spdlog::set_default_logger(NewDefaultLogger); + TheDefaultLogger = spdlog::default_logger_raw(); } spdlog::logger& Get(std::string_view Name) { std::shared_ptr<spdlog::logger> Logger = spdlog::get(std::string(Name)); + if (!Logger) { - Logger = std::make_shared<spdlog::logger>(std::string(Name), - begin(spdlog::default_logger()->sinks()), - end(spdlog::default_logger()->sinks())); - - Logger->set_level(spdlog::default_logger()->level()); + Logger = Default().clone(std::string(Name)); spdlog::register_logger(Logger); } @@ -57,6 +58,7 @@ ConsoleLog() void InitializeLogging() { + TheDefaultLogger = spdlog::default_logger_raw(); } void |