Skip to content

Commit

Permalink
Merge pull request #2 from LethalCompanyModding/reorg
Browse files Browse the repository at this point in the history
Reorganizes Rules and adds links to Docs for rules
  • Loading branch information
RobynLlama authored Aug 2, 2024
2 parents 29e2a60 + c41d594 commit 5c84486
Show file tree
Hide file tree
Showing 16 changed files with 85 additions and 44 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"bepin",
"bepinex",
"LCMXXXX",
"Ragdoll",
"skipcq"
]
}
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# LogMuncher

Munches Bepinex logs and sorts them by perceived severity

## Features
Pretty much just that. Use --help or -h to spit out command line switches, etc.
## Usage

See the [Documentation](https://lethalcompanymodding.github.io/Thunderstore/www/Tools/Log-Muncher.html#usage-and-arguments)
3 changes: 1 addition & 2 deletions src/LogMuncher/CheckRunners/AllChecksRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ internal class AllChecksRunner(string Source, string Content, string Level) : Ba

public override ICheckRunner[] MyChecks => checks;
private readonly ICheckRunner[] checks = [
//new RegexSourceRunner(Source),
new RegexSourceRunner(Source),
new RegexContentRunner(Content),
//new RegexLevelRunner(Level),
];

}
1 change: 1 addition & 0 deletions src/LogMuncher/CheckRunners/RegexContentRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ internal class RegexContentRunner(string Target) : BaseRegexCheckRunner(Target)
new BepinExVersionCheck(Target),
new ExceptionMatcherCheck(Target),
new NullRefMatcherCheck(Target),
new PlayerRagdollCheck(Target),
new SharingViolationCheck(Target),
];
}
3 changes: 2 additions & 1 deletion src/LogMuncher/CheckRunners/RegexSourceRunner.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using LogMuncher.Checks;
using dev.mamallama.checkrunnerlib.CheckRunners;
using LogMuncher.Checks.ContentChecks;

namespace LogMuncher.CheckRunners;

Expand All @@ -9,6 +10,6 @@ internal class RegexSourceRunner(string Target) : BaseRegexCheckRunner(Target)

public override ICheckRunner[] MyChecks => checks;
private readonly ICheckRunner[] checks = [

new HarmonySourceCheck(Target),
];
}
1 change: 1 addition & 0 deletions src/LogMuncher/Checks/BaseViolationCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ internal abstract class BaseViolationCheck(string Target, Violation MyViolation)
public readonly Violation MyViolation = MyViolation;
protected abstract CheckStatus ViolationLevel { get; }
public override ICheckRunner[] MyChecks => [];
public override string CheckID => "Violation Check";

public sealed override void RunChecks()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ internal class BepinExMultipleLoadsCheck(string Target) : BaseViolationCheck(Tar
{
private readonly static Violation SpecificViolation = new(
new("""skipping.*version exists""", RegexOptions.IgnoreCase | RegexOptions.Compiled, new(0, 0, 1)),
2002
20001
);

public override string CheckID => "BepinEx Multiple Loads";
protected override CheckStatus ViolationLevel => CheckStatus.Warning;
}
4 changes: 1 addition & 3 deletions src/LogMuncher/Checks/ContentChecks/BepinExVersionCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ internal class BepinExVersionCheck(string Target) : BaseViolationCheck(Target, S
{
private readonly static Violation SpecificViolation = new(
new("""bepinex \(.+\) and might not work""", RegexOptions.IgnoreCase | RegexOptions.Compiled, new(0, 0, 1)),
1000
00000
);

public override string CheckID => "BepinEx Version";
protected override CheckStatus ViolationLevel => CheckStatus.Warning;
}
4 changes: 1 addition & 3 deletions src/LogMuncher/Checks/ContentChecks/ExceptionMatcherCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ internal class ExceptionMatcherCheck(string Target) : BaseViolationCheck(Target,
{
private readonly static Violation SpecificViolation = new(
new("""[\s\w]*Exception""", RegexOptions.IgnoreCase | RegexOptions.Compiled, new(0, 0, 1)),
2000
40000
);

public override string CheckID => "Exception Matcher";
protected override CheckStatus ViolationLevel => CheckStatus.Warning;
}
4 changes: 1 addition & 3 deletions src/LogMuncher/Checks/ContentChecks/NullRefMatcherCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ internal class NullRefMatcherCheck(string Target) : BaseViolationCheck(Target, S
{
private readonly static Violation SpecificViolation = new(
new("""Object reference not set.*object""", RegexOptions.IgnoreCase | RegexOptions.Compiled, new(0, 0, 1)),
2001
20000
);

public override string CheckID => "NullRef Matcher";
protected override CheckStatus ViolationLevel => CheckStatus.Warning;
}
15 changes: 15 additions & 0 deletions src/LogMuncher/Checks/ContentChecks/PlayerRagdollCheck.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using dev.mamallama.checkrunnerlib.Checks;
using System.Text.RegularExpressions;
using LogMuncher.Muncher;

namespace LogMuncher.Checks.ContentChecks;

internal class PlayerRagdollCheck(string Target) : BaseViolationCheck(Target, SpecificViolation)
{
private readonly static Violation SpecificViolation = new(
new("""tag\W PlayerRagdoll\d* .+defined""", RegexOptions.IgnoreCase | RegexOptions.Compiled, new(0, 0, 1)),
00001
);

protected override CheckStatus ViolationLevel => CheckStatus.Warning;
}
4 changes: 1 addition & 3 deletions src/LogMuncher/Checks/ContentChecks/SharingViolationCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ internal class SharingViolationCheck(string Target) : BaseViolationCheck(Target,
{
private readonly static Violation SpecificViolation = new(
new("""sharing violation""", RegexOptions.IgnoreCase | RegexOptions.Compiled, new(0, 0, 1)),
2003
20002
);

public override string CheckID => "Sharing Violation";
protected override CheckStatus ViolationLevel => CheckStatus.Warning;
}
15 changes: 15 additions & 0 deletions src/LogMuncher/Checks/SourceChecks/HarmonyCheck.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using dev.mamallama.checkrunnerlib.Checks;
using System.Text.RegularExpressions;
using LogMuncher.Muncher;

namespace LogMuncher.Checks.ContentChecks;

internal class HarmonySourceCheck(string Target) : BaseViolationCheck(Target, SpecificViolation)
{
private readonly static Violation SpecificViolation = new(
new("""harmonyX?""", RegexOptions.IgnoreCase | RegexOptions.Compiled, new(0, 0, 1)),
35000
);

protected override CheckStatus ViolationLevel => CheckStatus.Warning;
}
18 changes: 13 additions & 5 deletions src/LogMuncher/Muncher/LineData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using LogMuncher.RuleDatabase;
using LogMuncher.CheckRunners;
using dev.mamallama.checkrunnerlib.CheckRunners;
using System.Net;
using System;

namespace LogMuncher.Muncher;

Expand Down Expand Up @@ -102,11 +100,21 @@ internal static void TraverseAndPrint(this ICheckRunner head, StringBuilder sb)
//cache the rule
var rule = Rules.GetRuleById(check.MyViolation.ErrorCode);

const string MatcherAddress = "https://lethalcompanymodding.github.io/Thunderstore/www/Tools/Log-Muncher.html#lcm-";

//Output Violation Name
sb.Append("- [LCM");
sb.Append(check.MyViolation.ErrorCode);
//Output Violation Name and link
sb.Append("- ");
sb.Append("""<a href= '""");
sb.Append(MatcherAddress);
sb.Append(check.MyViolation.ErrorCode.ToString("D4"));
sb.Append("' >");

sb.Append("[LCM");
sb.Append(check.MyViolation.ErrorCode.ToString("D4"));
sb.Append("] ");
sb.Append("""</a>""");

//Violation description
sb.Append(rule.Description);
sb.Append(" `");
sb.Append(rule.Type.GetStringDesc(rule.Value));
Expand Down
12 changes: 1 addition & 11 deletions src/LogMuncher/Muncher/LogMuncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
using System.Text;
using Markdig;
using LogMuncher.CheckRunners;
using LogMuncher.Checks;
using dev.mamallama.checkrunnerlib.Checks;

namespace LogMuncher.Muncher;
internal class TheLogMuncher(FileInfo Input, TextWriter Output) : IDisposable
Expand All @@ -28,14 +26,6 @@ internal class TheLogMuncher(FileInfo Input, TextWriter Output) : IDisposable
//For repeat log snipping
protected readonly List<int> AllErrorHashes = [];

//Todo List:
//Split this list into its own file
//Source: HarmonyX
//Output links to read more about a violation when printing
//assetbundleSystem.IO.FileNotFoundException
//Could not find * call in
//failed IL hook

protected static readonly Regex LineBreaker = new("""\[(debug|info|warning|message|fatal|error)\s*:([\s\w]+)\](.*)""", RegexOptions.IgnoreCase | RegexOptions.Compiled, new(0, 0, 1));

protected const float DefaultLogWeight = 0.1f;
Expand Down Expand Up @@ -77,7 +67,7 @@ public void MunchLog()
//Read context until next line
while (Input.Peek() != '[' && Input.Peek() != -1)
{
line += Input.ReadLine()?.ReplaceLineEndings("");
line += Input.ReadLine();//?.ReplaceLineEndings("");
addedLines++;
}

Expand Down
34 changes: 26 additions & 8 deletions src/LogMuncher/RuleDatabase/Rules-List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,43 @@ internal static partial class Rules
{
public static void Init()
{
RuleList.Add(1000,

//Ignorable non-issues 0000s

RuleList.Add(00000,
new(-15f, Muncher.CircumstanceType.Additive, "This warning is completely safe to ignore")
);

RuleList.Add(2000,
new(15f, Muncher.CircumstanceType.Additive, "Expression contains an Exception")
RuleList.Add(00001,
new(-15f, Muncher.CircumstanceType.Additive, "This error is completely safe to ignore")
);

RuleList.Add(2001,
//Slight Issues 1000s

//Moderate Errors 2000s

RuleList.Add(20000,
new(4f, Muncher.CircumstanceType.Additive, "Expression contains a null reference")
);

//BepinEx same plugin multiple times
RuleList.Add(2002,
new(5f, Muncher.CircumstanceType.Additive, "BepinEx is skipping a plugin because it already loaded it once")
RuleList.Add(20001,
new(6f, Muncher.CircumstanceType.Additive, "BepinEx is skipping a plugin because it already loaded it once")
);

RuleList.Add(2003,
new(5f, Muncher.CircumstanceType.Additive, "A file failed to load")
RuleList.Add(20002,
new(5f, Muncher.CircumstanceType.Additive, "A file failed to load due to a sharing violation")
);

//Serious errors 3000s
RuleList.Add(35000,
new(10f, Muncher.CircumstanceType.Additive, "Expression originates from HarmonyX, this is usually a bad sign")
);

//Critical errors 4000s

RuleList.Add(40000,
new(15f, Muncher.CircumstanceType.Additive, "Expression contains an Exception")
);
}
}

0 comments on commit 5c84486

Please sign in to comment.