Skip to content

Commit

Permalink
Add logging interface
Browse files Browse the repository at this point in the history
  • Loading branch information
blowfishpro committed Aug 29, 2017
1 parent 340d113 commit b1a8863
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Logging/IBasicLogger.cs
@@ -0,0 +1,15 @@
using System;
using UnityEngine;

namespace ModuleManager.Logging
{
// Stripped down version of UnityEngine.ILogger
public interface IBasicLogger
{
void Log(LogType logType, string message);
void Info(string message);
void Warning(string message);
void Error(string message);
void Exception(string message, Exception exception);
}
}
29 changes: 29 additions & 0 deletions Logging/ModLogger.cs
@@ -0,0 +1,29 @@
using System;
using UnityEngine;

namespace ModuleManager.Logging
{
public class ModLogger : IBasicLogger
{
private string prefix;
private ILogger logger;

public ModLogger(string prefix, ILogger logger)
{
this.prefix = "[" + prefix + "] ";
this.logger = logger;
}

public void Log(LogType logType, string message) => logger.Log(logType, prefix + message);

public void Info(string message) => Log(LogType.Log, message);
public void Warning(string message) => Log(LogType.Warning, message);
public void Error(string message) => Log(LogType.Error, message);

public void Exception(string message, Exception exception)
{
Error(message);
logger.LogException(exception);
}
}
}
2 changes: 2 additions & 0 deletions ModuleManager.csproj
Expand Up @@ -37,6 +37,8 @@
<Compile Include="Cats\CatOrbiter.cs" />
<Compile Include="Collections\ImmutableStack.cs" />
<Compile Include="Extensions\NodeStackExtensions.cs" />
<Compile Include="Logging\IBasicLogger.cs" />
<Compile Include="Logging\ModLogger.cs" />
<Compile Include="MMPatchLoader.cs" />
<Compile Include="ModuleManager.cs" />
<Compile Include="PatchContext.cs" />
Expand Down

0 comments on commit b1a8863

Please sign in to comment.