Skip to content

Commit 4c43d3c

Browse files
committed
Reworking the half baked log support I did years ago to something decent. No more gambiarras.
1 parent 24a35d5 commit 4c43d3c

13 files changed

Lines changed: 107 additions & 94 deletions

Source/ModuleManager/CustomConfigsManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ internal void Start()
3636
if (start_techtree_loaded)
3737
{
3838
if (HighLogic.CurrentGame.Parameters.Career.TechTreeUrl != TECHTREE_CONFIG.KspPath)
39-
Log(string.Format("Tech tree was changed by third party to [{0}].", HighLogic.CurrentGame.Parameters.Career.TechTreeUrl));
39+
Log("Tech tree was changed by third party to [{0}].", HighLogic.CurrentGame.Parameters.Career.TechTreeUrl);
4040
}
4141
else if (TECHTREE_CONFIG.IsLoadable)
4242
{
@@ -47,9 +47,9 @@ internal void Start()
4747
}
4848

4949
private static readonly KSPe.Util.Log.Logger log = KSPe.Util.Log.Logger.CreateThreadUnsafeForType<CustomConfigsManager>(); // No need to use thread safe logging. Yet.
50-
private static void Log(String s)
50+
private static void Log(String s, params object[] @params)
5151
{
52-
log.info(s);
52+
log.info(s, @params);
5353
}
5454

5555
}

Source/ModuleManager/Extensions/IBasicLoggerExtensions.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,19 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1414
You should have received a copy of the GNU General Public License 3.0
1515
along with Module Manager /L. If not, see <https://www.gnu.org/licenses/>.
1616
*/
17-
using System;
1817
using UnityEngine;
1918
using ModuleManager.Logging;
2019

20+
using K = KSPe.Util.Log;
21+
2122
namespace ModuleManager.Extensions
2223
{
2324
public static class IBasicLoggerExtensions
2425
{
25-
public static void Info(this IBasicLogger logger, string message) => logger.Log(LogType.Log, message);
26-
public static void Warning(this IBasicLogger logger, string message) => logger.Log(LogType.Warning, message);
27-
public static void Error(this IBasicLogger logger, string message) => logger.Log(LogType.Error, message);
26+
public static void Trace(this IBasicLogger logger, string message, params object[] @params) => logger.Log(K.Level.TRACE, message, @params);
27+
public static void Detail(this IBasicLogger logger, string message, params object[] @params) => logger.Log(K.Level.DETAIL, message, @params);
28+
public static void Info(this IBasicLogger logger, string message, params object[] @params) => logger.Log(K.Level.INFO, message, @params);
29+
public static void Warning(this IBasicLogger logger, string message, params object[] @params) => logger.Log(K.Level.WARNING, message, @params);
30+
public static void Error(this IBasicLogger logger, string message, params object[] @params) => logger.Log(K.Level.ERROR, message, @params);
2831
}
2932
}

Source/ModuleManager/Logging/IBasicLogger.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ You should have received a copy of the GNU General Public License 3.0
1515
along with Module Manager /L. If not, see <https://www.gnu.org/licenses/>.
1616
*/
1717
using System;
18-
using UnityEngine;
18+
19+
using K = KSPe.Util.Log;
1920

2021
namespace ModuleManager.Logging
2122
{
2223
// Stripped down version of UnityEngine.ILogger
2324
public interface IBasicLogger
2425
{
25-
void Log(LogType logType, string message);
26+
void Log(K.Level logType, string message, params object[] @params);
2627
void Exception(string message, Exception exception);
2728
void Finish();
2829
}

Source/ModuleManager/Logging/ModLogger.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ private ModLogger()
3939
this.methods[i++] = new LogMethod(LOG.error);
4040
}
4141

42-
// Gambiarra porque eu não previ essa possibilidade no KSPe.Util.Log!
43-
private static readonly object[] NONE = new object[0];
44-
public void Log(LogType logType, string message)
45-
{
46-
this.methods[(int)logType](message, NONE);
47-
}
42+
public void Log(K.Level logType, string message, params object[] @params) => this.methods[(int)logType](message, @params);
4843

4944
public void Exception(string message, Exception exception)
5045
{

Source/ModuleManager/Logging/PatchLogger.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace ModuleManager.Logging
2222
public class PatchLogger : IBasicLogger
2323
{
2424
internal readonly K.Logger log;
25+
internal static bool DebugMode => KSPe.Globals<ModuleManager>.DebugMode;
2526

2627
private delegate void LogMethod(string message, params object[] @parms);
2728
private readonly LogMethod[] methods;
@@ -36,16 +37,11 @@ internal PatchLogger(string filename)
3637
this.methods[i++] = new LogMethod(this.log.warn);
3738
this.methods[i++] = new LogMethod(this.log.info);
3839
this.methods[i++] = new LogMethod(this.log.detail);
39-
this.methods[i++] = new LogMethod(this.log.error);
40+
this.methods[i++] = new LogMethod(this.log.trace);
4041
this.log.level = K.Level.TRACE;
4142
}
4243

43-
// Gambiarra porque eu não previ essa possibilidade no KSPe.Util.Log!
44-
private static readonly object[] NONE = new object[0];
45-
public void Log(LogType logType, string message)
46-
{
47-
this.methods[(int)logType](message, NONE);
48-
}
44+
public void Log(K.Level logType, string message, object[] @params) => this.methods[(int)logType](message, @params);
4945

5046
public void Exception(string message, Exception exception)
5147
{

0 commit comments

Comments
 (0)