From 145b8be2a7e0e0a4655339406f8702cdb8c1940b Mon Sep 17 00:00:00 2001 From: Thorsten Sommer Date: Wed, 25 Feb 2026 07:48:00 +0100 Subject: [PATCH] Added conditional stdout logging for TerminalLogger --- .../Tools/TerminalLogger.cs | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/app/MindWork AI Studio/Tools/TerminalLogger.cs b/app/MindWork AI Studio/Tools/TerminalLogger.cs index f6801e8a..65bcca78 100644 --- a/app/MindWork AI Studio/Tools/TerminalLogger.cs +++ b/app/MindWork AI Studio/Tools/TerminalLogger.cs @@ -13,6 +13,7 @@ public sealed class TerminalLogger() : ConsoleFormatter(FORMATTER_NAME) public const string FORMATTER_NAME = "AI Studio Terminal Logger"; private static RustService? RUST_SERVICE; + private static bool LOG_TO_STDOUT = true; // Buffer for early log events before the RustService is available: private static readonly ConcurrentQueue EARLY_LOG_BUFFER = new(); @@ -44,6 +45,10 @@ public sealed class TerminalLogger() : ConsoleFormatter(FORMATTER_NAME) bufferedEvent.StackTrace ); } + + #if !DEBUG + LOG_TO_STDOUT = false; + #endif } public override void Write(in LogEntry logEntry, IExternalScopeProvider? scopeProvider, TextWriter textWriter) @@ -56,19 +61,22 @@ public sealed class TerminalLogger() : ConsoleFormatter(FORMATTER_NAME) var stackTrace = logEntry.Exception?.StackTrace; var colorCode = GetColorForLogLevel(logEntry.LogLevel); - textWriter.Write($"[{colorCode}{timestamp}{ANSI_RESET}] {colorCode}{logLevel}{ANSI_RESET} [{category}] {colorCode}{message}{ANSI_RESET}"); - if (logEntry.Exception is not null) + if (LOG_TO_STDOUT) { - textWriter.Write($" {colorCode}Exception: {exceptionMessage}{ANSI_RESET}"); - if (stackTrace is not null) + textWriter.Write($"[{colorCode}{timestamp}{ANSI_RESET}] {colorCode}{logLevel}{ANSI_RESET} [{category}] {colorCode}{message}{ANSI_RESET}"); + if (logEntry.Exception is not null) { - textWriter.WriteLine(); - foreach (var line in stackTrace.Split('\n')) - textWriter.WriteLine($" {colorCode}{line.TrimEnd()}{ANSI_RESET}"); + textWriter.Write($" {colorCode}Exception: {exceptionMessage}{ANSI_RESET}"); + if (stackTrace is not null) + { + textWriter.WriteLine(); + foreach (var line in stackTrace.Split('\n')) + textWriter.WriteLine($" {colorCode}{line.TrimEnd()}{ANSI_RESET}"); + } } + else + textWriter.WriteLine(); } - else - textWriter.WriteLine(); // Send log event to Rust via API (fire-and-forget): if (RUST_SERVICE is not null) @@ -90,4 +98,4 @@ public sealed class TerminalLogger() : ConsoleFormatter(FORMATTER_NAME) _ => ANSI_RESET }; -} \ No newline at end of file +}