diff --git a/Sources/Shared/Core/ITraceSink.h b/Sources/Shared/Core/ITraceSink.h index 74b257dc..4120fc6e 100644 --- a/Sources/Shared/Core/ITraceSink.h +++ b/Sources/Shared/Core/ITraceSink.h @@ -45,6 +45,9 @@ namespace Death /** @brief Unregisters the sink and uninitializes logger if no sink left */ void DetachSink(ITraceSink* sink); + + /** @brief Flushes and waits until all prior items are written to all sinks */ + void Flush(); } } diff --git a/Sources/Shared/Core/Logger.cpp b/Sources/Shared/Core/Logger.cpp index 3000c3c3..29fd1164 100644 --- a/Sources/Shared/Core/Logger.cpp +++ b/Sources/Shared/Core/Logger.cpp @@ -825,6 +825,11 @@ namespace Death { namespace Trace { _internalLogger.DetachSink(sink); } + void Flush() + { + _internalLogger.Flush(); + } + }} void DEATH_TRACE(TraceLevel level, const char* fmt, ...) diff --git a/Sources/nCine/Application.cpp b/Sources/nCine/Application.cpp index 92c635db..893c0c23 100644 --- a/Sources/nCine/Application.cpp +++ b/Sources/nCine/Application.cpp @@ -1010,7 +1010,7 @@ namespace nCine # if defined(WITH_BACKWARD) if (__consoleType >= ConsoleType::EscapeCodes) { - //__eh.FeatureFlags |= Backward::Flags::ColorizeOutput; + __eh.FeatureFlags |= Backward::Flags::ColorizeOutput; } # endif } @@ -1022,7 +1022,7 @@ namespace nCine if (__logFile = fs::Open(targetPath, FileAccess::Write)) { # if defined(WITH_BACKWARD) // Try to save crash info to log file - //__eh.Destination = static_cast(__logFile.get())->GetHandle(); + __eh.Destination = static_cast(__logFile.get())->GetHandle(); # endif } else { __logFile = nullptr; @@ -1094,6 +1094,16 @@ namespace nCine void Application::ShutdownTrace() { +# if !defined(DEATH_TARGET_EMSCRIPTEN) + if (__logFile != nullptr) { + Trace::Flush(); +# if defined(WITH_BACKWARD) + __eh.Destination = nullptr; +# endif + __logFile = nullptr; + } +# endif + Trace::DetachSink(this); # if defined(DEATH_TARGET_WINDOWS) && !defined(DEATH_TARGET_WINDOWS_RT)