Skip to content

Commit

Permalink
add - Added legacy debug log style
Browse files Browse the repository at this point in the history
---

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
  • Loading branch information
AptiviCEO committed Feb 10, 2024
1 parent b3311de commit 8cf269f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ public string KernelWideTimeZone
/// Shows an informational box for the program license for three seconds after each login
/// </summary>
public bool ShowLicenseInfoBox { get; set; } = true;
/// <summary>
/// Uses the legacy log style
/// </summary>
public bool DebugLegacyLogStyle { get; set; } = true;
#endregion

#region Colors
Expand Down
47 changes: 36 additions & 11 deletions public/Nitrocid/Kernel/Debugging/DebugWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ public static class DebugWriter
public static int DebugQuotaLines =>
Config.MainConfig.DebugQuotaLines;

/// <summary>
/// Uses the legacy log style
/// </summary>
public static bool DebugLegacyLogStyle =>
Config.MainConfig.DebugLegacyLogStyle;

/// <summary>
/// Outputs the text into the debugger file, and sets the time stamp. Censors all secure arguments if <see cref="DebugCensorPrivateInfo"/> is on.
/// </summary>
Expand Down Expand Up @@ -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++;
}

Expand All @@ -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;
}

Expand Down
6 changes: 6 additions & 0 deletions public/Nitrocid/Resources/Settings/SettingsEntries.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}
]
},
Expand Down

0 comments on commit 8cf269f

Please sign in to comment.