From 8cf269fdb88932fb43133fdce697ab834b13856d Mon Sep 17 00:00:00 2001 From: Aptivi CEO Date: Sat, 10 Feb 2024 11:51:06 +0300 Subject: [PATCH] add - Added legacy debug log style --- We've added legacy debug log style. We would like choice over limitation, so we've decided to turn this feature back on for consistency. The modern log style was for testing, and we found it to be stable, so we've decided to bring the legacy debug log style back. --- Type: add Breaking: False Doc Required: False Part: 1/1 --- .../Instances/KernelMainConfig.cs | 4 ++ .../Nitrocid/Kernel/Debugging/DebugWriter.cs | 47 ++++++++++++++----- .../Resources/Settings/SettingsEntries.json | 6 +++ 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/public/Nitrocid/Kernel/Configuration/Instances/KernelMainConfig.cs b/public/Nitrocid/Kernel/Configuration/Instances/KernelMainConfig.cs index 81d71101b2..abae8f296c 100644 --- a/public/Nitrocid/Kernel/Configuration/Instances/KernelMainConfig.cs +++ b/public/Nitrocid/Kernel/Configuration/Instances/KernelMainConfig.cs @@ -222,6 +222,10 @@ public string KernelWideTimeZone /// Shows an informational box for the program license for three seconds after each login /// public bool ShowLicenseInfoBox { get; set; } = true; + /// + /// Uses the legacy log style + /// + public bool DebugLegacyLogStyle { get; set; } = true; #endregion #region Colors diff --git a/public/Nitrocid/Kernel/Debugging/DebugWriter.cs b/public/Nitrocid/Kernel/Debugging/DebugWriter.cs index af8fb1b2c1..06643d0c46 100644 --- a/public/Nitrocid/Kernel/Debugging/DebugWriter.cs +++ b/public/Nitrocid/Kernel/Debugging/DebugWriter.cs @@ -79,6 +79,12 @@ public static class DebugWriter public static int DebugQuotaLines => Config.MainConfig.DebugQuotaLines; + /// + /// Uses the legacy log style + /// + public static bool DebugLegacyLogStyle => + Config.MainConfig.DebugLegacyLogStyle; + /// /// Outputs the text into the debugger file, and sets the time stamp. Censors all secure arguments if is on. /// @@ -151,14 +157,14 @@ public static void WriteDebugLogOnly(DebugLevel Level, string text, params objec CheckDebugQuota(); // Populate the debug stack frame - var STrace = new DebugStackFrameBasic(); + var STrace = new DebugStackFrame(); StringBuilder message = new(); // Descend a frame until we're out of this class int unwound = 0; while (STrace.RoutinePath.Contains(nameof(DebugWriter))) { - STrace = new DebugStackFrameBasic(unwound); + STrace = new DebugStackFrame(unwound); unwound++; } @@ -171,19 +177,38 @@ public static void WriteDebugLogOnly(DebugLevel Level, string text, params objec foreach (string splitText in texts) { string routinePath = STrace.RoutinePath; + string date = TimeDateTools.KernelDateTime.ToShortDateString(); + string time = TimeDateTools.KernelDateTime.ToShortTimeString(); - // Check to see if source file name is not empty. - if (routinePath != lastRoutinePath) + // We need to check to see if we're going to use the legacy log style + if (DebugLegacyLogStyle) + { + string routineName = STrace.RoutineName; + string fileName = STrace.RoutineFileName; + int fileLineNumber = STrace.RoutineLineNumber; + + // Check to see if source file name is not empty. + message.Append($"{date} {time} [{Level}] "); + if (fileName is not null && fileLineNumber != 0) + message.Append($"({routineName} - {fileName}:{fileLineNumber}): "); + message.Append($"{splitText}\n"); + } + else { - message.Append('\n'); - message.Append($"{TimeDateTools.KernelDateTime.ToShortDateString()} {TimeDateTools.KernelDateTime.ToShortTimeString()} "); - message.Append($"({routinePath})\n"); - message.Append(new string('-', message.Length - 2)); - message.Append($"\n\n"); + // Check to see if source routine is the same. + if (routinePath != lastRoutinePath) + { + string renderedRoutinePath = $"{date} {time} ({routinePath})"; + message.Append($"\n{renderedRoutinePath}\n"); + message.Append(new string('-', renderedRoutinePath.Length)); + message.Append($"\n\n"); + } + + // Show stack information + message.Append($"[{Level}] : {splitText}\n"); } - // Show stack information - message.Append($"[{Level}] : {splitText}\n"); + // Set teh last routine path for modern debug logs lastRoutinePath = routinePath; } diff --git a/public/Nitrocid/Resources/Settings/SettingsEntries.json b/public/Nitrocid/Resources/Settings/SettingsEntries.json index bdd4163ac2..9b604f90e7 100644 --- a/public/Nitrocid/Resources/Settings/SettingsEntries.json +++ b/public/Nitrocid/Resources/Settings/SettingsEntries.json @@ -212,6 +212,12 @@ "Type": "SBoolean", "Variable": "ShowLicenseInfoBox", "Description": "Whether to show the modal license information box for three seconds after each login. It's recommended to keep it on." + }, + { + "Name": "Legacy logging style for debug logs", + "Type": "SBoolean", + "Variable": "DebugLegacyLogStyle", + "Description": "Whether to enable the legacy logging style for debug logs or to enable grouped debug logs." } ] },