Skip to content

Commit 24a35d5

Browse files
committed
Transforming the whole LOGSPAM thingy into DETAIL logging. Now patch authors will not need a debug version of MM to debug what's happening with their patches.
1 parent 014eb97 commit 24a35d5

2 files changed

Lines changed: 19 additions & 63 deletions

File tree

Source/ModuleManager/MMPatchLoader.cs

Lines changed: 18 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -618,14 +618,10 @@ public static ConfigNode ModifyNode(NodeStack original, ConfigNode mod, PatchCon
618618

619619
#region Values
620620

621-
#if LOGSPAM
622621
string vals = "modding values";
623-
#endif
624622
foreach (ConfigNode.Value modVal in mod.values)
625623
{
626-
#if LOGSPAM
627624
vals += "\n " + modVal.name + "= " + modVal.value;
628-
#endif
629625

630626
Command cmd = CommandParser.Parse(modVal.name, out string valName);
631627

@@ -805,10 +801,8 @@ public static ConfigNode ModifyNode(NodeStack original, ConfigNode mod, PatchCon
805801

806802
if (value != null)
807803
{
808-
#if LOGSPAM
809804
if (origVal.value != value)
810805
vals += ": " + origVal.value + " -> " + value;
811-
#endif
812806

813807
if (cmd != Command.Copy)
814808
origVal.value = value;
@@ -900,9 +894,7 @@ public static ConfigNode ModifyNode(NodeStack original, ConfigNode mod, PatchCon
900894
break;
901895
}
902896
}
903-
#if LOGSPAM
904-
context.logger.Info(vals);
905-
#endif
897+
ModLogger.LOG.detail(vals);
906898

907899
#endregion Values
908900

@@ -977,9 +969,7 @@ public static ConfigNode ModifyNode(NodeStack original, ConfigNode mod, PatchCon
977969
string tag = "";
978970
string nodeType, nodeName;
979971
int index = 0;
980-
#if LOGSPAM
981-
string msg = "";
982-
#endif
972+
string logspam_msg = "";
983973
List<ConfigNode> subNodes = new List<ConfigNode>();
984974

985975
// three ways to specify:
@@ -1029,10 +1019,8 @@ public static ConfigNode ModifyNode(NodeStack original, ConfigNode mod, PatchCon
10291019
last = n;
10301020
}
10311021
}
1032-
#if LOGSPAM
10331022
else
1034-
msg += " cannot wildcard a % node: " + subMod.name + "\n";
1035-
#endif
1023+
logspam_msg += " cannot wildcard a % node: " + subMod.name + "\n";
10361024
}
10371025
else
10381026
{
@@ -1047,19 +1035,15 @@ public static ConfigNode ModifyNode(NodeStack original, ConfigNode mod, PatchCon
10471035
// if the original exists modify it
10481036
if (subNodes.Count > 0)
10491037
{
1050-
#if LOGSPAM
1051-
msg += " Applying subnode " + subMod.name + "\n";
1052-
#endif
1038+
logspam_msg += " Applying subnode " + subMod.name + "\n";
10531039
ConfigNode newSubNode = ModifyNode(nodeStack.Push(subNodes[0]), subMod, context);
10541040
subNodes[0].ShallowCopyFrom(newSubNode);
10551041
subNodes[0].name = newSubNode.name;
10561042
}
10571043
else
10581044
{
10591045
// if not add the mod node without the % in its name
1060-
#if LOGSPAM
1061-
msg += " Adding subnode " + subMod.name + "\n";
1062-
#endif
1046+
logspam_msg += " Adding subnode " + subMod.name + "\n";
10631047

10641048
ConfigNode copy = new ConfigNode(nodeType);
10651049

@@ -1074,9 +1058,7 @@ public static ConfigNode ModifyNode(NodeStack original, ConfigNode mod, PatchCon
10741058
{
10751059
if (subNodes.Count == 0)
10761060
{
1077-
#if LOGSPAM
1078-
msg += " Adding subnode " + subMod.name + "\n";
1079-
#endif
1061+
logspam_msg += " Adding subnode " + subMod.name + "\n";
10801062

10811063
ConfigNode copy = new ConfigNode(nodeType);
10821064

@@ -1090,16 +1072,12 @@ public static ConfigNode ModifyNode(NodeStack original, ConfigNode mod, PatchCon
10901072
else
10911073
{
10921074
// find each original subnode to modify, modify it and add the modified.
1093-
#if LOGSPAM
10941075
if (subNodes.Count == 0) // no nodes to modify!
1095-
msg += " Could not find node(s) to modify: " + subMod.name + "\n";
1096-
#endif
1076+
logspam_msg += " Could not find node(s) to modify: " + subMod.name + "\n";
10971077

10981078
foreach (ConfigNode subNode in subNodes)
10991079
{
1100-
#if LOGSPAM
1101-
msg += " Applying subnode " + subMod.name + "\n";
1102-
#endif
1080+
logspam_msg += " Applying subnode " + subMod.name + "\n";
11031081
ConfigNode newSubNode;
11041082
switch (command)
11051083
{
@@ -1126,9 +1104,7 @@ public static ConfigNode ModifyNode(NodeStack original, ConfigNode mod, PatchCon
11261104
}
11271105
}
11281106
}
1129-
#if LOGSPAM
1130-
context.logger.Info(msg);
1131-
#endif
1107+
ModLogger.LOG.detail(logspam_msg);
11321108
}
11331109
}
11341110

@@ -1191,9 +1167,7 @@ private static ConfigNode RecurseNodeSearch(string path, NodeStack nodeStack, Pa
11911167
return RecurseNodeSearch(path.Substring(3), nodeStack.Pop(), context);
11921168
}
11931169

1194-
#if LOGSPAM
1195-
context.logger.Info(string.Format("nextSep : \"{0}\" root : \"{1}\" nodeType : \"{2}\" nodeName : \"{3}\"", nextSep, root, nodeType, nodeName));
1196-
#endif
1170+
ModLogger.LOG.detail("nextSep : \"{0}\" root : \"{1}\" nodeType : \"{2}\" nodeName : \"{3}\"", nextSep, root, nodeType, nodeName);
11971171

11981172
// @XXXXX
11991173
if (root)
@@ -1525,14 +1499,10 @@ public static bool CheckConstraints(ConfigNode node, string constraints)
15251499
}
15261500
if (last != null)
15271501
{
1528-
#if LOGSPAM
15291502
print(string.Format("CheckConstraints: {0} {1}", constraints, (not ^ any)));
1530-
#endif
15311503
return not ^ any;
15321504
}
1533-
#if LOGSPAM
1534-
print(string.Format("CheckConstraints: {0} {1}", constraints, (not ^ false)));
1535-
#endif
1505+
ModLogger.LOG.detail("CheckConstraints: {0} {1}", constraints, (not ^ false));
15361506
return not ^ false;
15371507

15381508
case '#':
@@ -1541,14 +1511,10 @@ public static bool CheckConstraints(ConfigNode node, string constraints)
15411511
if (node.HasValue(type) && WildcardMatchValues(node, type, name))
15421512
{
15431513
bool ret2 = CheckConstraints(node, remainingConstraints);
1544-
#if LOGSPAM
1545-
print(string.Format("CheckConstraints: {0} {1}", constraints, ret2));
1546-
#endif
1514+
ModLogger.LOG.detail("CheckConstraints: {0} {1}", constraints, ret2);
15471515
return ret2;
15481516
}
1549-
#if LOGSPAM
1550-
print(string.Format("CheckConstraints: {0} false", constraints));
1551-
#endif
1517+
ModLogger.LOG.detail("CheckConstraints: {0} false", constraints);
15521518
return false;
15531519

15541520
case '~':
@@ -1557,28 +1523,20 @@ public static bool CheckConstraints(ConfigNode node, string constraints)
15571523
// or: ~breakingForce[100] will be true if it's present but not 100, too.
15581524
if (name == "" && node.HasValue(type))
15591525
{
1560-
#if LOGSPAM
1561-
print(string.Format("CheckConstraints: {0} false", constraints));
1562-
#endif
1526+
ModLogger.LOG.detail("CheckConstraints: {0} false", constraints);
15631527
return false;
15641528
}
15651529
if (name != "" && WildcardMatchValues(node, type, name))
15661530
{
1567-
#if LOGSPAM
1568-
print(string.Format("CheckConstraints: {0} false", constraints));
1569-
#endif
1531+
ModLogger.LOG.detail("CheckConstraints: {0} false", constraints);
15701532
return false;
15711533
}
15721534
bool ret = CheckConstraints(node, remainingConstraints);
1573-
#if LOGSPAM
1574-
print(string.Format("CheckConstraints: {0} {1}", constraints, ret));
1575-
#endif
1535+
ModLogger.LOG.detail("CheckConstraints: {0} {1}", constraints, ret);
15761536
return ret;
15771537

15781538
default:
1579-
#if LOGSPAM
1580-
print(string.Format("CheckConstraints: {0} false", constraints));
1581-
#endif
1539+
ModLogger.LOG.detail("CheckConstraints: {0} false", constraints);
15821540
return false;
15831541
}
15841542
}
@@ -1588,9 +1546,7 @@ public static bool CheckConstraints(ConfigNode node, string constraints)
15881546
{
15891547
ret3 = ret3 && CheckConstraints(node, constraint);
15901548
}
1591-
#if LOGSPAM
1592-
print(string.Format("CheckConstraints: {0} {1}", constraints, ret3));
1593-
#endif
1549+
ModLogger.LOG.detail("CheckConstraints: {0} {1}", constraints, ret3);
15941550
return ret3;
15951551
}
15961552

Source/ModuleManager/ModuleManager.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<DebugType>full</DebugType>
1818
<Optimize>False</Optimize>
1919
<OutputPath>..\..\bin\Debug\</OutputPath>
20-
<DefineConstants>DEBUG;LOGSPAM</DefineConstants>
20+
<DefineConstants>DEBUG</DefineConstants>
2121
<ErrorReport>prompt</ErrorReport>
2222
<WarningLevel>4</WarningLevel>
2323
<ConsolePause>False</ConsolePause>

0 commit comments

Comments
 (0)