Skip to content

Commit 75becc9

Browse files
committed
Adding KSPe Logging Facilities
1 parent ea123ef commit 75becc9

File tree

6 files changed

+34
-17
lines changed

6 files changed

+34
-17
lines changed

Source/ModuleManager/Cats/CatManager.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using UnityEngine;
3+
using K = KSPe.Util.Log;
34

45
namespace ModuleManager.Cats
56
{
@@ -98,7 +99,7 @@ private static GameObject LaunchCat(int scale)
9899

99100
trail.material = new Material(Shader.Find("Particles/Alpha Blended"));
100101

101-
Debug.Log("material = " + trail.material);
102+
LOG.info("material = {0}", trail.material);
102103
trail.material.mainTexture = rainbow;
103104
trail.time = 1.5f;
104105
trail.startWidth = 0.6f * scale * rainbow.height;
@@ -113,5 +114,7 @@ private static GameObject LaunchCat(int scale)
113114
cat.transform.localScale = 70 * scale * Vector3.one;
114115
return cat;
115116
}
116-
}
117+
118+
internal static readonly K.Logger LOG = K.Logger.CreateForType<CatAnimator>(true);
119+
}
117120
}

Source/ModuleManager/Cats/CatOrbiter.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ public void Init(CatOrbiter parent, float soi)
8585
double circularVel = Math.Sqrt(G * (Mass + parent.Mass) / dist.magnitude);
8686
if (parent == sun)
8787
circularVel *= Random.Range(0.9f, 1.1f);
88-
Debug.Log("CatOrbiter " + circularVel.ToString("F3") + " " + Mass.ToString("F2") + " " + orbiters[0].Mass.ToString("F2") + " " +
89-
dist.magnitude.ToString("F2"));
88+
CatManager.LOG.info("CatOrbiter {0} {1} {2} {3}", circularVel.ToString("F3"), Mass.ToString("F2"), orbiters[0].Mass.ToString("F2"), dist.magnitude.ToString("F2"));
9089

9190
Vector3d normal = (Random.value >= 0.3) ? Vector3d.back : Vector3d.forward;
9291

Source/ModuleManager/FatalErrorHandler.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ public static void HandleFatalError(string message)
2929
}
3030
catch(Exception ex)
3131
{
32-
Debug.LogError("Exception while trying to create the fatal exception dialog");
33-
Debug.LogException(ex);
32+
Logging.ModLogger.LOG.error(ex, "Exception while trying to create the fatal exception dialog");
3433
Application.Quit();
3534
}
3635
}
Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,38 @@
11
using System;
22
using UnityEngine;
33

4+
using K = KSPe.Util.Log;
5+
46
namespace ModuleManager.Logging
57
{
68
public class ModLogger : IBasicLogger
79
{
8-
private string prefix;
9-
private IBasicLogger logger;
10+
internal static readonly K.Logger LOG = K.Logger.CreateForType<ModuleManager>();
1011

11-
public ModLogger(string prefix, IBasicLogger logger)
12+
private delegate void LogMethod(string message, object[] parms);
13+
private readonly LogMethod[] methods;
14+
public ModLogger()
1215
{
13-
if (string.IsNullOrEmpty(prefix)) throw new ArgumentNullException(nameof(prefix));
14-
this.prefix = "[" + prefix + "] ";
15-
this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
16+
this.methods = new LogMethod[5];
17+
int i = 0;
18+
this.methods[i++] = new LogMethod(LOG.error);
19+
this.methods[i++] = new LogMethod(LOG.error);
20+
this.methods[i++] = new LogMethod(LOG.warn);
21+
this.methods[i++] = new LogMethod(LOG.info);
22+
this.methods[i++] = new LogMethod(LOG.error);
23+
LOG.level = K.Level.TRACE;
1624
}
1725

18-
public void Log(LogType logType, string message) => logger.Log(logType, prefix + message);
19-
public void Exception(string message, Exception exception) => logger.Exception(prefix + message, exception);
20-
}
26+
// Gambiarra porque eu não previ essa possibilidade no KSPe.Util.Log!
27+
private static readonly object[] NONE = new object[0];
28+
public void Log(LogType logType, string message)
29+
{
30+
this.methods[(int)logType](message, NONE);
31+
}
32+
33+
public void Exception(string message, Exception exception)
34+
{
35+
LOG.error(exception, message);
36+
}
37+
}
2138
}

Source/ModuleManager/MMPatchLoader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private void Awake()
7272
Instance = this;
7373
DontDestroyOnLoad(gameObject);
7474

75-
logger = new ModLogger("ModuleManager", new UnityLogger(Debug.unityLogger));
75+
logger = new ModLogger();
7676
}
7777

7878
private bool ready;

Source/ModuleManager/ModuleManager.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
<Compile Include="Logging\NormalMessage.cs" />
5454
<Compile Include="Logging\QueueLogger.cs" />
5555
<Compile Include="Collections\MessageQueue.cs" />
56-
<Compile Include="Logging\UnityLogger.cs" />
5756
<Compile Include="MMPatchLoader.cs" />
5857
<Compile Include="ModuleManager.cs" />
5958
<Compile Include="ModListGenerator.cs" />

0 commit comments

Comments
 (0)