Skip to content

Commit 5fe6303

Browse files
committed
Significant log messages refactoring, making good use of the message parametrizing.
1 parent e557263 commit 5fe6303

File tree

13 files changed

+175
-129
lines changed

13 files changed

+175
-129
lines changed

Source/ModuleManager/MMPatchLoader.cs

Lines changed: 58 additions & 44 deletions
Large diffs are not rendered by default.

Source/ModuleManager/ModListGenerator.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public static IEnumerable<string> GenerateModList(IEnumerable<ModAddedByAssembly
8585
}
8686
catch (Exception e)
8787
{
88-
progress.Exception(e, "Exception while generating SHA for assembly " + assemblyName.Name);
88+
progress.Exception(e, "Exception while generating SHA for assembly {0}", assemblyName.Name);
8989
}
9090

9191
modListInfo.AppendFormat(
@@ -126,8 +126,10 @@ public static IEnumerable<string> GenerateModList(IEnumerable<ModAddedByAssembly
126126
}
127127
catch (ArgumentOutOfRangeException)
128128
{
129-
progress.Error(cfgmod, "Skipping :FOR init for line " + name +
130-
". The line most likely contains a space that should be removed");
129+
progress.Error(cfgmod,
130+
"Skipping :FOR init for line {0}. The line most likely contains a space that should be removed",
131+
name
132+
);
131133
}
132134
}
133135
}
@@ -154,7 +156,7 @@ public static IEnumerable<string> GenerateModList(IEnumerable<ModAddedByAssembly
154156
}
155157
}
156158

157-
logger.Info(modListInfo.ToString());
159+
logger.Info("{0}", modListInfo);
158160

159161
mods.Sort();
160162

@@ -196,12 +198,12 @@ public static IEnumerable<ModAddedByAssembly> GetAdditionalModsFromStaticMethods
196198
string methodName = $"{ass.GetName().Name}.{type.Name}.{method.Name}()";
197199
try
198200
{
199-
logger.Info("Calling " + methodName);
201+
logger.Info("Calling {0}", methodName);
200202
IEnumerable<string> modsToAdd = (IEnumerable<string>)method.Invoke(null, null);
201203

202204
if (modsToAdd == null)
203205
{
204-
logger.Error("ModuleManagerAddToModList returned null: " + methodName);
206+
logger.Error("ModuleManagerAddToModList returned null: {0}", methodName);
205207
continue;
206208
}
207209

@@ -212,14 +214,14 @@ public static IEnumerable<ModAddedByAssembly> GetAdditionalModsFromStaticMethods
212214
}
213215
catch (Exception e)
214216
{
215-
logger.Exception(e, "Exception while calling " + methodName);
217+
logger.Exception(e, "Exception while calling {0}", methodName);
216218
}
217219
}
218220
}
219221
}
220222
catch (Exception e)
221223
{
222-
logger.Exception(e, "Add to mod list threw an exception in loading " + ass.FullName);
224+
logger.Exception(e, "Add to mod list threw an exception in loading {0}", ass.FullName);
223225
}
224226
}
225227

@@ -232,12 +234,12 @@ public static IEnumerable<ModAddedByAssembly> GetAdditionalModsFromStaticMethods
232234
string methodName = $"{obj.GetType().Name}.{method.Name}()";
233235
try
234236
{
235-
logger.Info("Calling " + methodName);
237+
logger.Info("Calling {0}", methodName);
236238
IEnumerable<string> modsToAdd = (IEnumerable<string>)method.Invoke(obj, null);
237239

238240
if (modsToAdd == null)
239241
{
240-
logger.Error("ModuleManagerAddToModList returned null: " + methodName);
242+
logger.Error("ModuleManagerAddToModList returned null: {0}", methodName);
241243
continue;
242244
}
243245

@@ -248,7 +250,7 @@ public static IEnumerable<ModAddedByAssembly> GetAdditionalModsFromStaticMethods
248250
}
249251
catch (Exception e)
250252
{
251-
logger.Exception(e, "Exception while calling " + methodName);
253+
logger.Exception(e, "Exception while calling {0}", methodName);
252254
}
253255
}
254256
}

Source/ModuleManager/ModuleManagerTestRunner.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@ public void RunTestCases(UrlDir gameDatabaseRoot)
4343
UrlDir.UrlFile parent = expect.parent;
4444
if (parent.configs.Count != expect.config.CountNodes + 1)
4545
{
46-
logger.Error("Test " + parent.name + " failed as expected number of nodes differs expected: " +
47-
expect.config.CountNodes + " found: " + (parent.configs.Count - 1));
46+
logger.Error(
47+
"Test {0} failed as expected number of nodes differs expected: {1} found: {2}",
48+
parent.name, expect.config.CountNodes, (parent.configs.Count - 1)
49+
);
4850
for (int i = 0; i < parent.configs.Count; ++i)
49-
logger.Info(parent.configs[i].config.ToString());
51+
logger.Detail("{0}", parent.configs[i].config);
5052
continue;
5153
}
5254
for (int i = 0; i < expect.config.CountNodes; ++i)
@@ -55,9 +57,10 @@ public void RunTestCases(UrlDir gameDatabaseRoot)
5557
ConfigNode expectNode = expect.config.nodes[i];
5658
if (!CompareRecursive(expectNode, gotNode))
5759
{
58-
logger.Error("Test " + parent.name + "[" + i +
59-
"] failed as expected output and actual output differ.\nexpected:\n" + expectNode +
60-
"\nActually got:\n" + gotNode);
60+
logger.Error(
61+
"Test {0}[{1}] failed as expected output and actual output differ.\nexpected:\n{2}\nActually got:\n{3}",
62+
parent.name, i, expectNode, gotNode
63+
);
6164
}
6265
}
6366

Source/ModuleManager/NeedsChecker.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ private void CheckNeedsRecursive(NodeStack nodeStack, UrlDir.UrlConfig urlConfig
154154
}
155155
catch (ArgumentOutOfRangeException e)
156156
{
157-
progress.Exception(e, "ArgumentOutOfRangeException in CheckNeeds for value \"" + val.name + "\"");
157+
progress.Exception(e, "ArgumentOutOfRangeException in CheckNeeds for value \"{0}\"", val.name);
158158
throw;
159159
}
160160
catch (Exception e)
161161
{
162-
progress.Exception(e, "General Exception in CheckNeeds for value \"" + val.name + "\"");
162+
progress.Exception(e, "General Exception in CheckNeeds for value \"{0}\"", val.name);
163163
throw;
164164
}
165165
}
@@ -171,7 +171,10 @@ private void CheckNeedsRecursive(NodeStack nodeStack, UrlDir.UrlConfig urlConfig
171171

172172
if (nodeName == null)
173173
{
174-
progress.Error(urlConfig, "Error - Node in file " + urlConfig.SafeUrl() + " subnode: " + nodeStack.GetPath() + " has config.name == null");
174+
progress.Error(urlConfig,
175+
"Error - Node in file {0} subnode: {1} has config.name == null",
176+
urlConfig.SafeUrl(), nodeStack.GetPath()
177+
);
175178
}
176179

177180
try
@@ -190,12 +193,12 @@ private void CheckNeedsRecursive(NodeStack nodeStack, UrlDir.UrlConfig urlConfig
190193
}
191194
catch (ArgumentOutOfRangeException e)
192195
{
193-
progress.Exception(e, "ArgumentOutOfRangeException in CheckNeeds for node \"" + node.name + "\"");
196+
progress.Exception(e, "ArgumentOutOfRangeException in CheckNeeds for node \"{0}\"", node.name);
194197
throw;
195198
}
196199
catch (Exception e)
197200
{
198-
progress.Exception(e, "General Exception " + e.GetType().Name + " for node \"" + node.name + "\"");
201+
progress.Exception(e, "General Exception {0} for node \"{1}\"", e.GetType().Name, node.name);
199202
throw;
200203
}
201204
}

Source/ModuleManager/PatchApplier.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ private void ApplyPatches(LinkedList<IProtoUrlConfig> databaseConfigs, IPass pas
6161
}
6262
catch (Exception e)
6363
{
64-
progress.Exception(e, patch.UrlConfig, "Exception while processing node : " + patch.UrlConfig.SafeUrl());
65-
logger.Error("Processed node was\n" + patch.UrlConfig.PrettyPrint());
64+
progress.Exception(e, patch.UrlConfig, "Exception while processing node : {0}", patch.UrlConfig.SafeUrl());
65+
logger.Error("Processed node was\n{0}", patch.UrlConfig.PrettyPrint());
6666
}
6767
}
6868
}

Source/ModuleManager/PatchExtractor.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,35 +59,35 @@ public IPatch ExtractPatch(UrlDir.UrlConfig urlConfig)
5959
{
6060
if (!urlConfig.type.IsBracketBalanced())
6161
{
62-
progress.Error(urlConfig, "Error - node name does not have balanced brackets (or a space - if so replace with ?):\n" + urlConfig.SafeUrl());
62+
progress.Error(urlConfig, "Error - node name does not have balanced brackets (or a space - if so replace with ?):\n{0}", urlConfig.SafeUrl());
6363
return null;
6464
}
6565

6666
Command command = CommandParser.Parse(urlConfig.type, out string name);
6767

6868
if (command == Command.Replace)
6969
{
70-
progress.Error(urlConfig, $"Error - replace command (%) is not valid on a root node: {urlConfig.SafeUrl()}");
70+
progress.Error(urlConfig, "Error - replace command (%) is not valid on a root node: {0}", urlConfig.SafeUrl());
7171
return null;
7272
}
7373
else if (command == Command.Create)
7474
{
75-
progress.Error(urlConfig, $"Error - create command (&) is not valid on a root node: {urlConfig.SafeUrl()}");
75+
progress.Error(urlConfig, "Error - create command (&) is not valid on a root node: {0}", urlConfig.SafeUrl());
7676
return null;
7777
}
7878
else if (command == Command.Rename)
7979
{
80-
progress.Error(urlConfig, $"Error - rename command (|) is not valid on a root node: {urlConfig.SafeUrl()}");
80+
progress.Error(urlConfig, "Error - rename command (|) is not valid on a root node: {0}", urlConfig.SafeUrl());
8181
return null;
8282
}
8383
else if (command == Command.Paste)
8484
{
85-
progress.Error(urlConfig, $"Error - paste command (#) is not valid on a root node: {urlConfig.SafeUrl()}");
85+
progress.Error(urlConfig, "Error - paste command (#) is not valid on a root node: {0}", urlConfig.SafeUrl());
8686
return null;
8787
}
8888
else if (command == Command.Special)
8989
{
90-
progress.Error(urlConfig, $"Error - special command (*) is not valid on a root node: {urlConfig.SafeUrl()}");
90+
progress.Error(urlConfig, "Error - special command (*) is not valid on a root node: {0}", urlConfig.SafeUrl());
9191
return null;
9292
}
9393

@@ -98,7 +98,10 @@ public IPatch ExtractPatch(UrlDir.UrlConfig urlConfig)
9898
}
9999
catch (FormatException ex)
100100
{
101-
progress.Error(urlConfig, $"Cannot parse node name as tag list: {ex.Message}\non: {urlConfig.SafeUrl()}");
101+
progress.Error(urlConfig,
102+
"Cannot parse node name as tag list: {0}\non: {1}",
103+
ex.Message, urlConfig.SafeUrl()
104+
);
102105
return null;
103106
}
104107

@@ -124,7 +127,7 @@ public IPatch ExtractPatch(UrlDir.UrlConfig urlConfig)
124127
}
125128
catch(Exception e)
126129
{
127-
progress.Exception(e, urlConfig, $"Exception while attempting to create patch from config: {urlConfig.SafeUrl()}");
130+
progress.Exception(e, urlConfig, "Exception while attempting to create patch from config: {0}", urlConfig.SafeUrl());
128131
return null;
129132
}
130133
}

Source/ModuleManager/Patches/CopyPatch.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ public void Apply(LinkedList<IProtoUrlConfig> databaseConfigs, IPatchProgress pr
5858
ConfigNode clone = MMPatchLoader.ModifyNode(this.log, new NodeStack(protoConfig.Node), UrlConfig.config, context);
5959
if (protoConfig.Node.GetValue("name") is string name && name == clone.GetValue("name"))
6060
{
61-
progress.Error(UrlConfig, $"Error - when applying copy {UrlConfig.SafeUrl()} to {protoConfig.FullUrl} - the copy needs to have a different name than the parent (use @name = xxx)");
61+
progress.Error(UrlConfig,
62+
"Error - when applying copy {0} to {1} - the copy needs to have a different name than the parent (use @name = xxx)",
63+
UrlConfig.SafeUrl(), protoConfig.FullUrl
64+
);
6265
}
6366
else
6467
{
@@ -68,7 +71,10 @@ public void Apply(LinkedList<IProtoUrlConfig> databaseConfigs, IPatchProgress pr
6871
}
6972
catch (Exception ex)
7073
{
71-
progress.Exception(ex, UrlConfig, $"Exception while applying copy {UrlConfig.SafeUrl()} to {protoConfig.FullUrl}");
74+
progress.Exception(ex, UrlConfig,
75+
"Exception while applying copy {0} to {1}",
76+
UrlConfig.SafeUrl(), protoConfig.FullUrl
77+
);
7278
}
7379
}
7480
}

Source/ModuleManager/Patches/DeletePatch.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ public void Apply(LinkedList<IProtoUrlConfig> databaseConfigs, IPatchProgress pr
6161
}
6262
catch (Exception ex)
6363
{
64-
progress.Exception(ex, UrlConfig, $"Exception while applying delete {UrlConfig.SafeUrl()} to {protoConfig.FullUrl}");
64+
progress.Exception(ex, UrlConfig,
65+
"Exception while applying delete {0} to {1}",
66+
UrlConfig.SafeUrl(), protoConfig.FullUrl
67+
);
6568
}
6669
}
6770
}

Source/ModuleManager/Patches/EditPatch.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,10 @@ public void Apply(LinkedList<IProtoUrlConfig> databaseConfigs, IPatchProgress pr
6969
}
7070
catch (Exception ex)
7171
{
72-
progress.Exception(ex, UrlConfig, $"Exception while applying update {UrlConfig.SafeUrl()} to {protoConfig.FullUrl}");
72+
progress.Exception(ex, UrlConfig,
73+
"Exception while applying update {0} to {1}",
74+
UrlConfig.SafeUrl(), protoConfig.FullUrl
75+
);
7376
}
7477
}
7578
}

0 commit comments

Comments
 (0)