aboutsummaryrefslogtreecommitdiff
path: root/src/zenutil/logging.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-12-19 12:06:13 +0100
committerGitHub <[email protected]>2023-12-19 12:06:13 +0100
commit519d942d809e740a3b1fe5a1f6a57a4cfe43408b (patch)
tree9b3c084e21bb7fd5e6bb3335e890647062d0703b /src/zenutil/logging.cpp
parentadded mimalloc_hooks (diff)
parentensure we can build without trace (#619) (diff)
downloadzen-273-integrated-memory-tracking.tar.xz
zen-273-integrated-memory-tracking.zip
Merge branch 'main' into 273-integrated-memory-tracking273-integrated-memory-tracking
Diffstat (limited to 'src/zenutil/logging.cpp')
-rw-r--r--src/zenutil/logging.cpp33
1 files changed, 18 insertions, 15 deletions
diff --git a/src/zenutil/logging.cpp b/src/zenutil/logging.cpp
index fedfdc7e8..64230ea81 100644
--- a/src/zenutil/logging.cpp
+++ b/src/zenutil/logging.cpp
@@ -23,6 +23,7 @@ ZEN_THIRD_PARTY_INCLUDES_END
namespace zen {
+static bool g_IsLoggingInitialized;
spdlog::sink_ptr g_FileSink;
spdlog::sink_ptr
@@ -83,6 +84,14 @@ BeginInitializeLogging(const LoggingOptions& LogOptions)
/* max size */ 128 * 1024 * 1024,
/* max files */ 16,
/* rotate on open */ true);
+ if (LogOptions.AbsLogFile.extension() == ".json")
+ {
+ FileSink->set_formatter(std::make_unique<logging::json_formatter>(LogOptions.LogId));
+ }
+ else
+ {
+ FileSink->set_formatter(std::make_unique<logging::full_formatter>(LogOptions.LogId)); // this will have a date prefix
+ }
}
std::set_terminate([]() { ZEN_CRITICAL("Program exited abnormally via std::terminate()"); });
@@ -173,31 +182,25 @@ FinishInitializeLogging(const LoggingOptions& LogOptions)
spdlog::set_formatter(
std::make_unique<logging::full_formatter>(LogOptions.LogId, std::chrono::system_clock::now())); // default to duration prefix
- if (g_FileSink)
- {
- if (LogOptions.AbsLogFile.extension() == ".json")
- {
- g_FileSink->set_formatter(std::make_unique<logging::json_formatter>(LogOptions.LogId));
- }
- else
- {
- g_FileSink->set_formatter(std::make_unique<logging::full_formatter>(LogOptions.LogId)); // this will have a date prefix
- }
- }
-
const std::string StartLogTime = zen::DateTime::Now().ToIso8601();
spdlog::apply_all([&](auto Logger) { Logger->info("log starting at {}", StartLogTime); });
+
+ g_IsLoggingInitialized = true;
}
void
ShutdownLogging()
{
- g_FileSink.reset();
+ if (g_IsLoggingInitialized)
+ {
+ auto DefaultLogger = zen::logging::Default();
+ ZEN_LOG_INFO(DefaultLogger, "log ending at {}", zen::DateTime::Now().ToIso8601());
+ }
- auto DefaultLogger = zen::logging::Default();
- ZEN_LOG_INFO(DefaultLogger, "log ending at {}", zen::DateTime::Now().ToIso8601());
zen::logging::ShutdownLogging();
+
+ g_FileSink.reset();
}
} // namespace zen