Skip to content

Commit

Permalink
[Logger++] Added enabling full stack traces for logs.
Browse files Browse the repository at this point in the history
  • Loading branch information
kafeijao committed Jun 15, 2023
1 parent 81ee6cf commit 7c5b760
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
30 changes: 30 additions & 0 deletions Logger++/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,36 @@ public override void OnApplicationEarlyStart() {

ModConfig.InitializeMelonPrefs();

var defaultStackLogTypeError = Application.GetStackTraceLogType(LogType.Error);
if (ModConfig.MeFullStackForErrors.Value) Application.SetStackTraceLogType(LogType.Error, StackTraceLogType.Full);
ModConfig.MeFullStackForErrors.OnEntryValueChanged.Subscribe((_, newValue) => {
Application.SetStackTraceLogType(LogType.Error, newValue ? StackTraceLogType.Full : defaultStackLogTypeError);
});

var defaultStackLogTypeAssert = Application.GetStackTraceLogType(LogType.Assert);
if (ModConfig.MeFullStackForAsserts.Value) Application.SetStackTraceLogType(LogType.Assert, StackTraceLogType.Full);
ModConfig.MeFullStackForAsserts.OnEntryValueChanged.Subscribe((_, newValue) => {
Application.SetStackTraceLogType(LogType.Assert, newValue ? StackTraceLogType.Full : defaultStackLogTypeAssert);
});

var defaultStackLogTypeException = Application.GetStackTraceLogType(LogType.Exception);
if (ModConfig.MeFullStackForExceptions.Value) Application.SetStackTraceLogType(LogType.Exception, StackTraceLogType.Full);
ModConfig.MeFullStackForExceptions.OnEntryValueChanged.Subscribe((_, newValue) => {
Application.SetStackTraceLogType(LogType.Exception, newValue ? StackTraceLogType.Full : defaultStackLogTypeException);
});

var defaultStackLogTypeWarning = Application.GetStackTraceLogType(LogType.Warning);
if (ModConfig.MeFullStackForWarnings.Value) Application.SetStackTraceLogType(LogType.Warning, StackTraceLogType.Full);
ModConfig.MeFullStackForWarnings.OnEntryValueChanged.Subscribe((_, newValue) => {
Application.SetStackTraceLogType(LogType.Warning, newValue ? StackTraceLogType.Full : defaultStackLogTypeWarning);
});

var defaultStackLogTypeLog = Application.GetStackTraceLogType(LogType.Log);
if (ModConfig.MeFullStackForLogs.Value) Application.SetStackTraceLogType(LogType.Log, StackTraceLogType.Full);
ModConfig.MeFullStackForLogs.OnEntryValueChanged.Subscribe((_, newValue) => {
Application.SetStackTraceLogType(LogType.Log, newValue ? StackTraceLogType.Full : defaultStackLogTypeLog);
});

Application.logMessageReceived += LogMessageReceived;
Application.logMessageReceivedThreaded += LogMessageReceived;

Expand Down
21 changes: 21 additions & 0 deletions Logger++/ModConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ public static class ModConfig {
internal static MelonPreferences_Entry<bool> MeShowSpamMessages;
internal static MelonPreferences_Entry<bool> MeShowUselessMessages;

internal static MelonPreferences_Entry<bool> MeFullStackForErrors;
internal static MelonPreferences_Entry<bool> MeFullStackForExceptions;
internal static MelonPreferences_Entry<bool> MeFullStackForAsserts;
internal static MelonPreferences_Entry<bool> MeFullStackForWarnings;
internal static MelonPreferences_Entry<bool> MeFullStackForLogs;

public static void InitializeMelonPrefs() {

// Melon Config
Expand Down Expand Up @@ -74,6 +80,21 @@ public static void InitializeMelonPrefs() {

MeShowUselessMessages = _melonCategory.CreateEntry("ShowUselessMessages", false,
description: "Whether only show known useless logs or not.");

MeFullStackForErrors = _melonCategory.CreateEntry("FullStackForErrors", false,
description: "Whether the Error logs will include full stack traces or not.");

MeFullStackForExceptions = _melonCategory.CreateEntry("FullStackForExceptions", false,
description: "Whether the Exceptions logs will include full stack traces or not.");

MeFullStackForAsserts = _melonCategory.CreateEntry("FullStackForAsserts", false,
description: "Whether the Asserts logs will include full stack traces or not.");

MeFullStackForWarnings = _melonCategory.CreateEntry("FullStackForWarnings", false,
description: "Whether the Warnings logs will include full stack traces or not.");

MeFullStackForLogs = _melonCategory.CreateEntry("FullStackForLogs", false,
description: "Whether the Info logs will include full stack traces or not.");
}

}
2 changes: 1 addition & 1 deletion Logger++/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
namespace Kafe.LoggerPlusPlus.Properties;
internal static class AssemblyInfoParams {
public const string Name = "Logger++";
public const string Version = "0.0.3";
public const string Version = "0.0.4";
public const string Author = "kafeijao";
}
4 changes: 3 additions & 1 deletion Logger++/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
**Note:** This is a **__plugin__**, it goes in the `/Plugins` folder, not the ~~`/Mods`~~ one!

This **Plugin** allows you to pick some extra logs to be forwarded to the melon console. No more error messages will be
lost in the player log!
lost in the player log! Note that some of these logs might miss some information, like the IL offset so check the trace
on the `Player.log` if you need that information.

## Features
- Bring logging from the game logs to the Melon Console.
Expand All @@ -28,6 +29,7 @@ lost in the player log!
- AvPro messages: *off by default*
- Known SPAM-y messages: *off by default*
- Known pointless messages: *off by default*
- Enable full logs with full stack trace for all types of message (info/warnings/errors) in Melon Prefs.

---

Expand Down

0 comments on commit 7c5b760

Please sign in to comment.