-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING CHANGE: Logger no longer requires plugin specific logger and logs using class name instead of plugin name.
- Loading branch information
Showing
8 changed files
with
82 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,70 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using BepInEx.Logging; | ||
using UnityEngine; | ||
|
||
namespace PiUtils.Util; | ||
|
||
public class PluginLogger | ||
{ | ||
private ManualLogSource logger; | ||
public static Dictionary<string, ManualLogSource> loggers = new Dictionary<string, ManualLogSource>(); | ||
|
||
private string prefix; | ||
private ManualLogSource logger | ||
{ | ||
get | ||
{ | ||
if (loggers.ContainsKey(prefix)) | ||
{ | ||
return loggers[prefix]; | ||
} | ||
|
||
public PluginLogger(ManualLogSource logger, string prefix) | ||
var logger = BepInEx.Logging.Logger.CreateLogSource(prefix); | ||
loggers.Add(prefix, logger); | ||
return logger; | ||
} | ||
} | ||
|
||
public PluginLogger(string prefix) | ||
{ | ||
this.logger = logger; | ||
this.prefix = prefix; | ||
} | ||
public PluginLogger(ManualLogSource logger, Type type) | ||
|
||
public PluginLogger(Type type) : this(type.FullName) | ||
{ | ||
this.logger = logger; | ||
prefix = type.FullName; | ||
} | ||
|
||
public static PluginLogger GetLogger<T>(ManualLogSource logger) | ||
public static PluginLogger GetLogger<T>() | ||
{ | ||
return new PluginLogger(logger, typeof(T)); | ||
return new PluginLogger(typeof(T)); | ||
} | ||
|
||
public void LogInfo(string message) | ||
{ | ||
logger.LogInfo($"[{prefix}] ({Time.frameCount}) {message}"); | ||
logger.LogInfo($"<{Time.frameCount}> {message}"); | ||
} | ||
|
||
public void LogDebug(string message) | ||
{ | ||
logger.LogDebug($"[{prefix}] ({Time.frameCount}) {message}"); | ||
logger.LogDebug($"<{Time.frameCount}> {message}"); | ||
} | ||
|
||
public void LogWarning(string message) | ||
{ | ||
logger.LogWarning($"[{prefix}] ({Time.frameCount}) {message}"); | ||
logger.LogWarning($"<{Time.frameCount}> {message}"); | ||
} | ||
|
||
public void LogError(string message) | ||
{ | ||
logger.LogError($"[{prefix}] ({Time.frameCount}) {message}"); | ||
logger.LogError($"<{Time.frameCount}> {message}"); | ||
} | ||
|
||
internal void LogTrace(string v) | ||
public void LogTrace(string v) | ||
{ | ||
if (!ModConfig.TraceLogEnabled()) | ||
{ | ||
return; | ||
} | ||
logger.LogDebug($"[{prefix}] ({Time.frameCount}) {v}"); | ||
logger.LogDebug($"<{Time.frameCount}> {v}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters