aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/logging.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zencore/logging.cpp')
-rw-r--r--src/zencore/logging.cpp31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/zencore/logging.cpp b/src/zencore/logging.cpp
index 900da6c6d..3206e380b 100644
--- a/src/zencore/logging.cpp
+++ b/src/zencore/logging.cpp
@@ -21,14 +21,35 @@
# pragma section(".zlog$z", read)
#endif
+namespace {
+
+// Bootstrap logger: a minimal stdout logger that exists for the entire lifetime
+// of the process. TheDefaultLogger points here before InitializeLogging() runs
+// (and is restored here after ShutdownLogging()) so that log macros always have
+// a usable target — no null checks or lazy init required on the common path.
+zen::Ref<zen::logging::Logger> s_BootstrapLogger = [] {
+ zen::logging::SinkPtr Sink(new zen::logging::AnsiColorStdoutSink());
+ return zen::Ref<zen::logging::Logger>(new zen::logging::Logger("", Sink));
+}();
+
+} // namespace
+
namespace zen {
-LoggerRef TheDefaultLogger;
+LoggerRef TheDefaultLogger{*s_BootstrapLogger};
} // namespace zen
namespace zen::logging {
+static bool g_LoggingInitialized = false;
+
+bool
+IsLoggingInitialized()
+{
+ return g_LoggingInitialized;
+}
+
//////////////////////////////////////////////////////////////////////////
LoggerRef
@@ -232,7 +253,7 @@ GetLogLevel()
LoggerRef
Default()
{
- ZEN_ASSERT(TheDefaultLogger, "logging::InitializeLogging() must be called before using the logger");
+ ZEN_ASSERT(g_LoggingInitialized, "logging::InitializeLogging() must be called before using the logger");
return TheDefaultLogger;
}
@@ -393,7 +414,8 @@ InitializeLogging()
{
ZEN_MEMSCOPE(ELLMTag::Logging);
- TheDefaultLogger = LoggerRef(*Registry::Instance().DefaultLoggerRaw());
+ TheDefaultLogger = LoggerRef(*Registry::Instance().DefaultLoggerRaw());
+ g_LoggingInitialized = true;
}
void
@@ -401,8 +423,9 @@ ShutdownLogging()
{
ZEN_MEMSCOPE(ELLMTag::Logging);
+ g_LoggingInitialized = false;
Registry::Instance().Shutdown();
- TheDefaultLogger = {};
+ TheDefaultLogger = LoggerRef(*s_BootstrapLogger);
}
bool