Skip to content

Commit 102cff3

Browse files
committed
Ressurrecting the Patch logger, using new facilities from KSPe.util.Log
1 parent 52ac9e3 commit 102cff3

File tree

6 files changed

+53
-1
lines changed

6 files changed

+53
-1
lines changed

Source/ModuleManager/FilePathRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ internal static class FilePathRepository
1313
internal static readonly KspConfig PART_DATABASE = new KspConfig("PartDatabase");
1414

1515
internal static readonly string MMCfgOutputPath = KSPe.IO.File<ModuleManager>.Data.Solve("_MMCfgOutput");
16+
internal static readonly string PATCH_LOG_FILENAME = "MMPatch";
1617
}
1718
}

Source/ModuleManager/Logging/IBasicLogger.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ public interface IBasicLogger
88
{
99
void Log(LogType logType, string message);
1010
void Exception(string message, Exception exception);
11+
void Finish();
1112
}
1213
}

Source/ModuleManager/Logging/ModLogger.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@ public void Exception(string message, Exception exception)
3636
{
3737
LOG.error(exception, message);
3838
}
39+
40+
public void Finish() { }
3941
}
4042
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using System;
2+
using UnityEngine;
3+
4+
using K = KSPe.Util.Log;
5+
6+
namespace ModuleManager.Logging
7+
{
8+
public class PatchLogger : IBasicLogger
9+
{
10+
internal readonly K.Logger log;
11+
12+
private delegate void LogMethod(string message, params object[] @parms);
13+
private readonly LogMethod[] methods;
14+
internal PatchLogger(string filename)
15+
{
16+
this.log = new K.FileChainUnityLogger<Startup>(filename);
17+
18+
this.methods = new LogMethod[6];
19+
int i = 0;
20+
this.methods[i++] = new LogMethod(this.log.error);
21+
this.methods[i++] = new LogMethod(this.log.error);
22+
this.methods[i++] = new LogMethod(this.log.warn);
23+
this.methods[i++] = new LogMethod(this.log.info);
24+
this.methods[i++] = new LogMethod(this.log.detail);
25+
this.methods[i++] = new LogMethod(this.log.error);
26+
this.log.level = K.Level.TRACE;
27+
}
28+
29+
// Gambiarra porque eu não previ essa possibilidade no KSPe.Util.Log!
30+
private static readonly object[] NONE = new object[0];
31+
public void Log(LogType logType, string message)
32+
{
33+
this.methods[(int)logType](message, NONE);
34+
}
35+
36+
public void Exception(string message, Exception exception)
37+
{
38+
this.log.error(exception, message);
39+
}
40+
41+
public void Finish()
42+
{
43+
this.log.Close();
44+
}
45+
}
46+
}

Source/ModuleManager/MMPatchLoader.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public IEnumerable<IProtoUrlConfig> Run()
7979
if (!ModuleManager.IsLoadedFromCache)
8080
#pragma warning restore CS0618 // Type or member is obsolete
8181
{
82-
IBasicLogger patchLogger = ModLogger.Instance;
82+
IBasicLogger patchLogger = new PatchLogger(FilePathRepository.PATCH_LOG_FILENAME);
8383

8484
IPatchProgress progress = new PatchProgress(patchLogger);
8585
status = "Pre patch init";
@@ -181,6 +181,7 @@ public IEnumerable<IProtoUrlConfig> Run()
181181
CreateCache(databaseConfigs, progress.Counter.patchedNodes);
182182
}
183183

184+
patchLogger.Finish();
184185
StatusUpdate(progress);
185186

186187
#endregion Saving Cache

Source/ModuleManager/ModuleManager.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
<Compile Include="GUI\Menu.12.cs" />
136136
<Compile Include="GUI\ReloadingDatabase.12.cs" />
137137
<Compile Include="Utils\PerformanceMetrics.cs" />
138+
<Compile Include="Logging\PatchLogger.cs" />
138139
</ItemGroup>
139140
<ItemGroup>
140141
<Reference Include="System" />

0 commit comments

Comments
 (0)