diff options
| author | Stefan Boberg <[email protected]> | 2023-05-02 10:01:47 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-05-02 10:01:47 +0200 |
| commit | 075d17f8ada47e990fe94606c3d21df409223465 (patch) | |
| tree | e50549b766a2f3c354798a54ff73404217b4c9af /src/zencore/logging.cpp | |
| parent | fix: bundle shouldn't append content zip to zen (diff) | |
| download | zen-075d17f8ada47e990fe94606c3d21df409223465.tar.xz zen-075d17f8ada47e990fe94606c3d21df409223465.zip | |
moved source directories into `/src` (#264)
* moved source directories into `/src`
* updated bundle.lua for new `src` path
* moved some docs, icon
* removed old test trees
Diffstat (limited to 'src/zencore/logging.cpp')
| -rw-r--r-- | src/zencore/logging.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/src/zencore/logging.cpp b/src/zencore/logging.cpp new file mode 100644 index 000000000..a6423e2dc --- /dev/null +++ b/src/zencore/logging.cpp @@ -0,0 +1,85 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#include "zencore/logging.h" + +#include <spdlog/sinks/stdout_color_sinks.h> + +namespace zen { + +// We shadow the underlying spdlog default logger, in order to avoid a bunch of overhead +spdlog::logger* TheDefaultLogger; + +} // namespace zen + +namespace zen::logging { + +spdlog::logger& +Default() +{ + 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 = Default().clone(std::string(Name)); + spdlog::register_logger(Logger); + } + + return *Logger; +} + +std::once_flag ConsoleInitFlag; +std::shared_ptr<spdlog::logger> ConLogger; + +spdlog::logger& +ConsoleLog() +{ + std::call_once(ConsoleInitFlag, [&] { + ConLogger = spdlog::stdout_color_mt("console"); + + ConLogger->set_pattern("%v"); + }); + + return *ConLogger; +} + +std::shared_ptr<spdlog::logger> TheErrorLogger; + +spdlog::logger* +ErrorLog() +{ + return TheErrorLogger.get(); +} + +void +SetErrorLog(std::shared_ptr<spdlog::logger>&& NewErrorLogger) +{ + TheErrorLogger = std::move(NewErrorLogger); +} + +void +InitializeLogging() +{ + TheDefaultLogger = spdlog::default_logger_raw(); +} + +void +ShutdownLogging() +{ + spdlog::drop_all(); + spdlog::shutdown(); +} + +} // namespace zen::logging |