Skip to content

Commit

Permalink
convert filters to lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
CptMoore committed Jan 19, 2025
1 parent dbb3ffb commit d59be20
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 3 deletions.
63 changes: 61 additions & 2 deletions ModTek/Features/Logging/AppenderSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,67 @@ internal class AppenderSettings

[JsonProperty]
internal readonly string PrefixesToIgnore_Description = $"Ignore any lines starting with any of the listed prefixes, internally will be converted to {nameof(Excludes)}.";
[JsonProperty]
internal string[] PrefixesToIgnore;

[JsonProperty] internal string[] PrefixesToIgnore =
[
"Unity [ERROR] Desired shader compiler platform",
"Unity [LOG] Look rotation viewing vector is zero",
"Unity [ERROR] Material doesn't have a color property",
"Unity [WARNING] Parent of RectTransform is being set with parent property",
"Unity [WARNING] The referenced script",
"Unity [WARNING] Rejecting unit",
"Unity [WARNING] Parent of RectTransform is being set with parent property",
"Unity [WARNING] No DefaultCombatLeaderCastDefId specified for faction [Player1sMercUnit]",
"Unity [WARNING] No DefaultCombatLeaderCastDefId specified for faction [Player2sMercUnit]",
"Unity [ERROR] Bones do not match bindpose.",
"Unity [ERROR] ================== ERROR! Found missing transforms",
"Unity [WARNING] ERROR! Couldn't auto-setup",
"Unity [WARNING] Could not retrieve member",
"MapExport [ERROR] Out of bounds",
"CombatLog.Hit [LOG] ???????? DIRECTION:",
"Unity [WARNING] BoxColliders does not support negative scale or size",
"AudioEvents [DEBUG] Audio Engine",
"MechEngineer [LOG] Auto fixing chassisDef",
"AudioEvents [DEBUG] OnApplicationFocus",
"NetworkRandomValues [DEBUG] Seed",
"NetworkRandomCallstacks [DEBUG] Seed",
"UserSettings [DEBUG] Using existing cloud settings from save manager",
"BattleTech.Services [DEBUG] [BattleTechParadoxAPI]",
"Network.Client [LOG] Connection",
"GameInfo [LOG] DEVELOPMENT FLAG NOT SET",
"MechEngineer [LOG] settings loaded",
"GameInfo [LOG] ProductName: BATTLETECH",
"GameInfo [LOG] RELEASE FLAG SET",
"DebugBridge",
"CustomComponents [LOG] [CC]SimpleCustom",
"LoginManager [LOG] Successfully authenticated with OPS. Moving onto ComStar connection proper.",
"Data.AssetBundleManager [LOG] Trying to load AssetBundle:",
"UserSettings [LOG] [LOG] User settings saved",
"MechLab [WARNING] GetWeaponPrefabName failed to find a prefab name for unit",
"Analytics [WARNING] Analytics Event requested with invalid IP",
"Analytics [WARNING] Request next called but no servers have been found",
"Analytics [WARNING] Request next called but reporting is disabled",
"UI [WARNING] Singleton UIManagerFader",
"CombatLog.Initialization [WARNING] Turret",
"MechEngineer [WARNING] Unsupported weapon category for 667",
"MechEngineer [WARNING] Unsupported weapon category for 666",
"CustomComponents [DEBUG] [CC]Mech validation for NULL return",
"CustomComponents [DEBUG] [CC]-- CustomComponents.Flags",
"CustomComponents [DEBUG] [CC]-- CustomComponents.AutoLinked",
"CustomComponents.UnitType [DEBUG]",
"Data.DataManager [WARNING] LoadRequest for",
"LewdableTanks [DEBUG] Fixing cost of",
"CombatLog.Initialization [ERROR] Error instantiating VFX",
"PilotDef [WARNING] PilotDef already did Init From Save!",
"Achievements [LOG]",
"DataLoader [DEBUG] Loading:",
"Save.Core.SaveSystem [DEBUG]",
"Unity [ERROR] Generating SIM GAME UID while still loading!",
"Unity [WARNING] HBS Tooltip on UI Element",
"HarmonyX [TRACE]",
"HarmonyX [LOG]",
"Unity [ERROR] RenderTexture.Create failed: format unsupported for random writes"
];

[JsonProperty]
internal const string AbsoluteTimeEnabled_Description = "Adds the clock time.";
Expand Down
57 changes: 56 additions & 1 deletion ModTek/Features/Logging/Filters.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Linq;
using System;
using System.Linq;
using HBS.Logging;

namespace ModTek.Features.Logging;

Expand Down Expand Up @@ -26,8 +28,61 @@ internal Filters(AppenderSettings settings)
}
}

private static readonly string s_loggerNameModTek = string.Intern("ModTek");
private static readonly string s_loggerNameMechEngineer = string.Intern("MechEngineer");
private static readonly string s_loggerNameCustomFilters = string.Intern("CustomFilters");
internal bool IsIncluded(ref MTLoggerMessageDto messageDto)
{
var loggerName = messageDto.LoggerName;
var logLevel = messageDto.LogLevel;
var message = messageDto.Message;

{ // Filter 1 - Includes

// includes
if (!ReferenceEquals(loggerName, s_loggerNameMechEngineer)
&& !ReferenceEquals(loggerName, s_loggerNameCustomFilters))
{
return false;
}

if (logLevel != LogLevel.Debug && logLevel != LogLevel.Log)
{
return false;
}
var length = message.Length;
const string sw1 = "This ";
const int sw1Length = 6;
sw1.StartsWith()
if (length >= 17 && SequenceStartsWith(message, 0, sw1Length, sw1))
{
const string sw2 = "is Test.";
if (SequenceStartsWith(message, sw1Length, sw2))
{
return true;
}

const string sw3 = "was a Test.";
if (length >= 20 && SequenceStartsWith(message, sw1Length, sw3))
{
switch (message[19])
{
case '!':
case '.':
return true;
}
}
}
return false;
}

{ // Filter 1 - Excludes
if (ReferenceEquals(loggerName, s_loggerNameModTek))
{
return false;
}
}

if (_includeFilters != null)
{
var found = false;
Expand Down
22 changes: 22 additions & 0 deletions ModTek/Features/Logging/Trie.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Text.RegularExpressions;

Expand Down Expand Up @@ -54,6 +55,27 @@ internal Regex CompileRegex()
return new Regex(sb.ToString(), RegexOptions.Compiled);
}

internal Func<string, bool> CompileLambda()
{
var inputParameter = Expression.Parameter(typeof(string), "input");

var sb = new StringBuilder();
var traverser = new Traverser
{
enteredNode = node => sb.Append(node.prefixPart),
enteringFirstSibling = node => sb.Append("(?:"),
enteringNextSibling = node => sb.Append("|"),
exitedLastSibling = node => sb.Append(")")
};
Traverse(traverser);
Expression.Variable()
Expression.Constant()
Expression.GreaterThan()
return new Regex(sb.ToString(), RegexOptions.Compiled);

return Expression.Lambda<Func<string, bool>>(lastExpression, inputParameter).Compile();
}

private class Traverser
{
internal Action<Node> enteredNode;
Expand Down

0 comments on commit d59be20

Please sign in to comment.