Browse Source

Moved Logging to new location

pull/46/head
Anairkoen Schno 6 years ago
parent
commit
b35f4bfa1d
18 changed files with 666 additions and 87 deletions
  1. +1
    -2
      IPA.Injector/Bootstrapper.cs
  2. +4
    -3
      IPA.Injector/Injector.cs
  3. +0
    -34
      IPA.Loader/IllusionInjector/Logging/UnityLogInterceptor.cs
  4. +2
    -2
      IPA.Loader/IllusionInjector/Updating/ModsaberML/ApiEndpoint.cs
  5. +2
    -2
      IPA.Loader/IllusionInjector/Updating/ModsaberML/Updater.cs
  6. +1
    -2
      IPA.Loader/IllusionInjector/Updating/SelfPlugin.cs
  7. +97
    -0
      IPA.Loader/Loader/Composite/CompositeBSPlugin.cs
  8. +77
    -0
      IPA.Loader/Loader/Composite/CompositeIPAPlugin.cs
  9. +109
    -0
      IPA.Loader/Loader/PluginComponent.cs
  10. +305
    -0
      IPA.Loader/Loader/PluginManager.cs
  11. +1
    -1
      IPA.Loader/Logging/LogPrinter.cs
  12. +13
    -1
      IPA.Loader/Logging/Logger.cs
  13. +6
    -7
      IPA.Loader/Logging/Printers/ColoredConsolePrinter.cs
  14. +2
    -2
      IPA.Loader/Logging/Printers/GZFilePrinter.cs
  15. +5
    -6
      IPA.Loader/Logging/Printers/GlobalLogFilePrinter.cs
  16. +4
    -5
      IPA.Loader/Logging/Printers/PluginLogFilePrinter.cs
  17. +4
    -20
      IPA.Loader/Logging/StandardLogger.cs
  18. +33
    -0
      IPA.Loader/Logging/UnityLogInterceptor.cs

+ 1
- 2
IPA.Injector/Bootstrapper.cs View File

@ -1,5 +1,4 @@
using IllusionInjector.Logging;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


+ 4
- 3
IPA.Injector/Injector.cs View File

@ -1,11 +1,12 @@
using IllusionInjector;
using IllusionInjector.Logging;
using IPA.Loader;
using IPA.Logging;
using System;
using System.IO;
using System.Reflection;
using UnityEngine;
using static IllusionPlugin.Logging.Logger;
using Logger = IllusionInjector.Logging.Logger;
using static IPA.Logging.Logger;
using Logger = IPA.Logging.Logger;
namespace IPA.Injector
{


+ 0
- 34
IPA.Loader/IllusionInjector/Logging/UnityLogInterceptor.cs View File

@ -1,34 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using LoggerBase = IllusionPlugin.Logging.Logger;
namespace IllusionInjector.Logging
{
public class UnityLogInterceptor
{
public static LoggerBase Unitylogger = new StandardLogger("UnityEngine");
public static LoggerBase.Level LogTypeToLevel(LogType type)
{
switch (type)
{
case LogType.Assert:
return LoggerBase.Level.Debug;
case LogType.Error:
return LoggerBase.Level.Error;
case LogType.Exception:
return LoggerBase.Level.Critical;
case LogType.Log:
return LoggerBase.Level.Info;
case LogType.Warning:
return LoggerBase.Level.Warning;
default:
return LoggerBase.Level.Info;
}
}
}
}

+ 2
- 2
IPA.Loader/IllusionInjector/Updating/ModsaberML/ApiEndpoint.cs View File

@ -1,5 +1,5 @@
using IllusionInjector.Logging;
using IllusionInjector.Utilities;
using IPA.Logging;
using IPA.Utilities;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System;


+ 2
- 2
IPA.Loader/IllusionInjector/Updating/ModsaberML/Updater.cs View File

@ -1,5 +1,5 @@
using IllusionInjector.Updating.Backup;
using IllusionInjector.Utilities;
using IPA.Utilities;
using IPA.Loader;
using Ionic.Zip;
using Newtonsoft.Json;
@ -16,7 +16,7 @@ using System.Threading;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Networking;
using Logger = IllusionInjector.Logging.Logger;
using Logger = IPA.Logging.Logger;
namespace IllusionInjector.Updating.ModsaberML
{


+ 1
- 2
IPA.Loader/IllusionInjector/Updating/SelfPlugin.cs View File

@ -1,5 +1,4 @@
using IllusionPlugin;
using IPA;
using IPA;
using System;
using System.Collections.Generic;
using System.Linq;


+ 97
- 0
IPA.Loader/Loader/Composite/CompositeBSPlugin.cs View File

@ -0,0 +1,97 @@
using IPA;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine.SceneManagement;
using Logger = IPA.Logging.Logger;
namespace IPA.Loader.Composite
{
public class CompositeBSPlugin : IBeatSaberPlugin
{
IEnumerable<IBeatSaberPlugin> plugins;
private delegate void CompositeCall(IBeatSaberPlugin plugin);
public CompositeBSPlugin(IEnumerable<IBeatSaberPlugin> plugins) {
this.plugins = plugins;
}
public void OnApplicationStart() {
Invoke(plugin => plugin.OnApplicationStart());
}
public void OnApplicationQuit() {
Invoke(plugin => plugin.OnApplicationQuit());
}
public void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode) {
foreach (var plugin in plugins) {
try {
plugin.OnSceneLoaded(scene, sceneMode);
}
catch (Exception ex) {
Logger.log.Error($"{plugin.Name}: {ex}");
}
}
}
public void OnSceneUnloaded(Scene scene) {
foreach (var plugin in plugins) {
try {
plugin.OnSceneUnloaded(scene);
}
catch (Exception ex) {
Logger.log.Error($"{plugin.Name}: {ex}");
}
}
}
public void OnActiveSceneChanged(Scene prevScene, Scene nextScene) {
foreach (var plugin in plugins) {
try {
plugin.OnActiveSceneChanged(prevScene, nextScene);
}
catch (Exception ex) {
Logger.log.Error($"{plugin.Name}: {ex}");
}
}
}
private void Invoke(CompositeCall callback) {
foreach (var plugin in plugins) {
try {
callback(plugin);
}
catch (Exception ex) {
Logger.log.Error($"{plugin.Name}: {ex}");
}
}
}
public void OnUpdate() {
Invoke(plugin => plugin.OnUpdate());
}
public void OnFixedUpdate() {
Invoke(plugin => plugin.OnFixedUpdate());
}
public string Name => throw new NotImplementedException();
public string Version => throw new NotImplementedException();
public Uri UpdateUri => throw new NotImplementedException();
public ModsaberModInfo ModInfo => throw new NotImplementedException();
public void OnLateUpdate() {
Invoke(plugin => {
if (plugin is IEnhancedBeatSaberPlugin)
((IEnhancedBeatSaberPlugin) plugin).OnLateUpdate();
});
}
}
}

+ 77
- 0
IPA.Loader/Loader/Composite/CompositeIPAPlugin.cs View File

@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using IPA;
using IPA.Old;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine.SceneManagement;
using Logger = IPA.Logging.Logger;
namespace IPA.Loader.Composite
{
#pragma warning disable CS0618 // Type or member is obsolete
public class CompositeIPAPlugin : IPlugin
{
IEnumerable<IPlugin> plugins;
private delegate void CompositeCall(IPlugin plugin);
public CompositeIPAPlugin(IEnumerable<IPlugin> plugins) {
this.plugins = plugins;
}
public void OnApplicationStart() {
Invoke(plugin => plugin.OnApplicationStart());
}
public void OnApplicationQuit() {
Invoke(plugin => plugin.OnApplicationQuit());
}
private void Invoke(CompositeCall callback) {
foreach (var plugin in plugins) {
try {
callback(plugin);
}
catch (Exception ex) {
Logger.log.Error($"{plugin.Name}: {ex}");
}
}
}
public void OnUpdate() {
Invoke(plugin => plugin.OnUpdate());
}
public void OnFixedUpdate() {
Invoke(plugin => plugin.OnFixedUpdate());
}
public string Name {
get { throw new NotImplementedException(); }
}
public string Version {
get { throw new NotImplementedException(); }
}
public void OnLateUpdate() {
Invoke(plugin => {
if (plugin is IEnhancedBeatSaberPlugin)
((IEnhancedBeatSaberPlugin) plugin).OnLateUpdate();
});
}
public void OnLevelWasLoaded(int level)
{
Invoke(plugin => plugin.OnLevelWasLoaded(level));
}
public void OnLevelWasInitialized(int level)
{
Invoke(plugin => plugin.OnLevelWasInitialized(level));
}
}
#pragma warning restore CS0618 // Type or member is obsolete
}

+ 109
- 0
IPA.Loader/Loader/PluginComponent.cs View File

@ -0,0 +1,109 @@
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using UnityEngine.SceneManagement;
using IPA.Loader;
using IPA.Loader.Composite;
using IPA.Logging;
namespace IPA.Loader
{
public class PluginComponent : MonoBehaviour
{
private CompositeBSPlugin bsPlugins;
private CompositeIPAPlugin ipaPlugins;
private bool quitting = false;
public static PluginComponent Create()
{
Application.logMessageReceived += delegate (string condition, string stackTrace, LogType type)
{
var level = UnityLogInterceptor.LogTypeToLevel(type);
UnityLogInterceptor.UnityLogger.Log(level, $"{condition.Trim()}");
UnityLogInterceptor.UnityLogger.Log(level, $"{stackTrace.Trim()}");
};
return new GameObject("IPA_PluginManager").AddComponent<PluginComponent>();
}
void Awake()
{
DontDestroyOnLoad(gameObject);
bsPlugins = new CompositeBSPlugin(PluginManager.BSPlugins);
ipaPlugins = new CompositeIPAPlugin(PluginManager.Plugins);
gameObject.AddComponent<IllusionInjector.Updating.ModsaberML.Updater>();
bsPlugins.OnApplicationStart();
ipaPlugins.OnApplicationStart();
SceneManager.activeSceneChanged += OnActiveSceneChanged;
SceneManager.sceneLoaded += OnSceneLoaded;
SceneManager.sceneUnloaded += OnSceneUnloaded;
}
void Update()
{
bsPlugins.OnUpdate();
ipaPlugins.OnUpdate();
}
void LateUpdate()
{
bsPlugins.OnLateUpdate();
ipaPlugins.OnLateUpdate();
}
void FixedUpdate()
{
bsPlugins.OnFixedUpdate();
ipaPlugins.OnFixedUpdate();
}
void OnDestroy()
{
if (!quitting)
{
Create();
}
}
void OnApplicationQuit()
{
SceneManager.activeSceneChanged -= OnActiveSceneChanged;
SceneManager.sceneLoaded -= OnSceneLoaded;
SceneManager.sceneUnloaded -= OnSceneUnloaded;
bsPlugins.OnApplicationQuit();
ipaPlugins.OnApplicationQuit();
quitting = true;
}
void OnLevelWasLoaded(int level)
{
ipaPlugins.OnLevelWasLoaded(level);
}
public void OnLevelWasInitialized(int level)
{
ipaPlugins.OnLevelWasInitialized(level);
}
void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode)
{
bsPlugins.OnSceneLoaded(scene, sceneMode);
}
private void OnSceneUnloaded(Scene scene) {
bsPlugins.OnSceneUnloaded(scene);
}
private void OnActiveSceneChanged(Scene prevScene, Scene nextScene) {
bsPlugins.OnActiveSceneChanged(prevScene, nextScene);
}
}
}

+ 305
- 0
IPA.Loader/Loader/PluginManager.cs View File

@ -0,0 +1,305 @@
using IllusionInjector.Updating;
using IPA;
using IPA.Logging;
using IPA.Old;
using IPA.Utilities;
using Mono.Cecil;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace IPA.Loader
{
public static class PluginManager
{
#pragma warning disable CS0618 // Type or member is obsolete (IPlugin)
public class BSPluginMeta
{
public IBeatSaberPlugin Plugin { get; internal set; }
public string Filename { get; internal set; }
public ModsaberModInfo ModsaberInfo { get; internal set; }
}
public static IEnumerable<IBeatSaberPlugin> BSPlugins
{
get
{
if(_bsPlugins == null)
{
LoadPlugins();
}
return _bsPlugins.Select(p => p.Plugin);
}
}
private static List<BSPluginMeta> _bsPlugins = null;
internal static IEnumerable<BSPluginMeta> BSMetas
{
get
{
if (_bsPlugins == null)
{
LoadPlugins();
}
return _bsPlugins;
}
}
public static IEnumerable<IPlugin> Plugins
{
get
{
if (_ipaPlugins == null)
{
LoadPlugins();
}
return _ipaPlugins;
}
}
private static List<IPlugin> _ipaPlugins = null;
private static void LoadPlugins()
{
string pluginDirectory = Path.Combine(Environment.CurrentDirectory, "Plugins");
// Process.GetCurrentProcess().MainModule crashes the game and Assembly.GetEntryAssembly() is NULL,
// so we need to resort to P/Invoke
string exeName = Path.GetFileNameWithoutExtension(AppInfo.StartupPath);
Logger.log.Info(exeName);
_bsPlugins = new List<BSPluginMeta>();
_ipaPlugins = new List<IPlugin>();
if (!Directory.Exists(pluginDirectory)) return;
string cacheDir = Path.Combine(pluginDirectory, ".cache");
if (!Directory.Exists(cacheDir))
{
Directory.CreateDirectory(cacheDir);
}
else
{
foreach (string plugin in Directory.GetFiles(cacheDir, "*"))
{
File.Delete(plugin);
}
}
//Copy plugins to .cache
string[] originalPlugins = Directory.GetFiles(pluginDirectory, "*.dll");
foreach (string s in originalPlugins)
{
string pluginCopy = Path.Combine(cacheDir, Path.GetFileName(s));
File.Copy(Path.Combine(pluginDirectory, s), pluginCopy);
}
var selfPlugin = new BSPluginMeta
{
Filename = Path.Combine(Environment.CurrentDirectory, "IPA.exe"),
Plugin = new SelfPlugin()
};
selfPlugin.ModsaberInfo = selfPlugin.Plugin.ModInfo;
_bsPlugins.Add(selfPlugin);
//Load copied plugins
string[] copiedPlugins = Directory.GetFiles(cacheDir, "*.dll");
foreach (string s in copiedPlugins)
{
var result = LoadPluginsFromFile(s, exeName);
_bsPlugins.AddRange(result.Item1);
_ipaPlugins.AddRange(result.Item2);
}
// DEBUG
Logger.log.Info($"Running on Unity {UnityEngine.Application.unityVersion}");
Logger.log.Info($"Game version {UnityEngine.Application.version}");
Logger.log.Info("-----------------------------");
Logger.log.Info($"Loading plugins from {LoneFunctions.GetRelativePath(pluginDirectory, Environment.CurrentDirectory)} and found {_bsPlugins.Count + _ipaPlugins.Count}");
Logger.log.Info("-----------------------------");
foreach (var plugin in _bsPlugins)
{
Logger.log.Info($"{plugin.Plugin.Name}: {plugin.Plugin.Version}");
}
Logger.log.Info("-----------------------------");
foreach (var plugin in _ipaPlugins)
{
Logger.log.Info($"{plugin.Name}: {plugin.Version}");
}
Logger.log.Info("-----------------------------");
}
private static Tuple<IEnumerable<BSPluginMeta>, IEnumerable<IPlugin>> LoadPluginsFromFile(string file, string exeName)
{
List<BSPluginMeta> bsPlugins = new List<BSPluginMeta>();
List<IPlugin> ipaPlugins = new List<IPlugin>();
if (!File.Exists(file) || !file.EndsWith(".dll", true, null))
return new Tuple<IEnumerable<BSPluginMeta>, IEnumerable<IPlugin>>(bsPlugins, ipaPlugins);
T OptionalGetPlugin<T>(Type t) where T : class
{
// use typeof() to allow for easier renaming (in an ideal world this compiles to a string, but ¯\_(ツ)_/¯)
if (t.GetInterface(typeof(T).Name) != null)
{
try
{
T pluginInstance = Activator.CreateInstance(t) as T;
string[] filter = null;
if (pluginInstance is IGenericEnhancedPlugin)
{
filter = ((IGenericEnhancedPlugin)pluginInstance).Filter;
}
if (filter == null || filter.Contains(exeName, StringComparer.OrdinalIgnoreCase))
return pluginInstance;
}
catch (Exception e)
{
Logger.log.Error($"Could not load plugin {t.FullName} in {Path.GetFileName(file)}! {e}");
}
}
return null;
}
try
{
#region Fix assemblies for refactor
var module = ModuleDefinition.ReadModule(file);
bool modifiedModule = false;
foreach (var @ref in module.AssemblyReferences)
{ // fix assembly references
if (@ref.Name == "IllusionPlugin" || @ref.Name == "IllusionInjector")
{
@ref.Name = "IPA.Loader";
modifiedModule = true;
}
}
if (modifiedModule)
{ // types don't need to be fixed if it's already referencing the new version
foreach (var @ref in module.GetTypeReferences())
{ // fix type references
if (@ref.FullName == "IllusionPlugin.IPlugin") @ref.Namespace = "IPA.Old"; //@ref.Name = "";
if (@ref.FullName == "IllusionPlugin.IEnhancedPlugin") @ref.Namespace = "IPA.Old"; //@ref.Name = "";
if (@ref.FullName == "IllusionPlugin.IBeatSaberPlugin") @ref.Namespace = "IPA"; //@ref.Name = "";
if (@ref.FullName == "IllusionPlugin.IEnhancedBeatSaberPlugin") @ref.Namespace = "IPA"; //@ref.Name = "";
if (@ref.FullName == "IllusionPlugin.BeatSaber.ModsaberModInfo") @ref.Namespace = "IPA"; //@ref.Name = "";
if (@ref.FullName == "IllusionPlugin.IniFile") @ref.Namespace = "IPA"; //@ref.Name = "";
if (@ref.FullName == "IllusionPlugin.IModPrefs") @ref.Namespace = "IPA"; //@ref.Name = "";
if (@ref.FullName == "IllusionPlugin.ModPrefs") @ref.Namespace = "IPA"; //@ref.Name = "";
if (@ref.FullName == "IllusionPlugin.Utils.ReflectionUtil") @ref.Namespace = "IPA.Utilities"; //@ref.Name = "";
if (@ref.FullName == "IllusionPlugin.Logging.Logger") @ref.Namespace = "IPA.Logging"; //@ref.Name = "";
if (@ref.FullName == "IllusionPlugin.Logging.LogPrinter") @ref.Namespace = "IPA.Logging"; //@ref.Name = "";
if (@ref.FullName == "IllusionInjector.PluginManager") @ref.Namespace = "IPA.Loader"; //@ref.Name = "";
if (@ref.FullName == "IllusionInjector.PluginComponent") @ref.Namespace = "IPA.Loader"; //@ref.Name = "";
if (@ref.FullName == "IllusionInjector.CompositeBSPlugin") @ref.Namespace = "IPA.Loader.Composite"; //@ref.Name = "";
if (@ref.FullName == "IllusionInjector.CompositeIPAPlugin") @ref.Namespace = "IPA.Loader.Composite"; //@ref.Name = "";
if (@ref.FullName == "IllusionInjector.Logging.UnityLogInterceptor") @ref.Namespace = "IPA.Logging"; //@ref.Name = "";
if (@ref.FullName == "IllusionInjector.Logging.StandardLogger") @ref.Namespace = "IPA.Logging"; //@ref.Name = "";
if (@ref.Namespace == "IllusionInjector.Utilities") @ref.Namespace = "IPA.Utilities"; //@ref.Name = "";
if (@ref.Namespace == "IllusionInjector.Logging.Printers") @ref.Namespace = "IPA.Logging.Printers"; //@ref.Name = "";
}
module.Write(file);
}
#endregion
Assembly assembly = Assembly.LoadFrom(file);
foreach (Type t in assembly.GetTypes())
{
IBeatSaberPlugin bsPlugin = OptionalGetPlugin<IBeatSaberPlugin>(t);
if (bsPlugin != null)
{
try
{
var init = t.GetMethod("Init", BindingFlags.Instance | BindingFlags.Public);
if (init != null)
{
var initArgs = new List<object>();
var initParams = init.GetParameters();
Logger modLogger = null;
IModPrefs modPrefs = null;
foreach (var param in initParams)
{
var ptype = param.ParameterType;
if (ptype.IsAssignableFrom(typeof(Logger))) {
if (modLogger == null) modLogger = new StandardLogger(bsPlugin.Name);
initArgs.Add(modLogger);
}
else if (ptype.IsAssignableFrom(typeof(IModPrefs)))
{
if (modPrefs == null) modPrefs = new ModPrefs(bsPlugin);
initArgs.Add(modPrefs);
}
else
initArgs.Add(ptype.GetDefault());
}
init.Invoke(bsPlugin, initArgs.ToArray());
}
bsPlugins.Add(new BSPluginMeta
{
Plugin = bsPlugin,
Filename = file.Replace("\\.cache", ""), // quick and dirty fix
ModsaberInfo = bsPlugin.ModInfo
});
}
catch (AmbiguousMatchException)
{
Logger.log.Error($"Only one Init allowed per plugin");
}
}
else
{
IPlugin ipaPlugin = OptionalGetPlugin<IPlugin>(t);
if (ipaPlugin != null)
{
ipaPlugins.Add(ipaPlugin);
}
}
}
}
catch (Exception e)
{
Logger.log.Error($"Could not load {Path.GetFileName(file)}! {e}");
}
return new Tuple<IEnumerable<BSPluginMeta>, IEnumerable<IPlugin>>(bsPlugins, ipaPlugins);
}
public class AppInfo
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto, ExactSpelling = false)]
private static extern int GetModuleFileName(HandleRef hModule, StringBuilder buffer, int length);
private static HandleRef NullHandleRef = new HandleRef(null, IntPtr.Zero);
public static string StartupPath
{
get
{
StringBuilder stringBuilder = new StringBuilder(260);
GetModuleFileName(NullHandleRef, stringBuilder, stringBuilder.Capacity);
return stringBuilder.ToString();
}
}
}
#pragma warning restore CS0618 // Type or member is obsolete (IPlugin)
}
}

IPA.Loader/IllusionPlugin/Logging/LogPrinter.cs → IPA.Loader/Logging/LogPrinter.cs View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IllusionPlugin.Logging
namespace IPA.Logging
{
/// <summary>
/// The log printer's base class.

IPA.Loader/IllusionPlugin/Logging/Logger.cs → IPA.Loader/Logging/Logger.cs View File

@ -4,13 +4,25 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IllusionPlugin.Logging
namespace IPA.Logging
{
/// <summary>
/// The logger base class. Provides the format for console logs.
/// </summary>
public abstract class Logger
{
private static Logger _log;
internal static Logger log
{
get
{
if (_log == null)
_log = new StandardLogger("IPA");
return _log;
}
}
internal static bool LogCreated => _log != null;
/// <summary>
/// The standard format for log messages.
/// </summary>

IPA.Loader/IllusionInjector/Logging/Printers/ColoredConsolePrinter.cs → IPA.Loader/Logging/Printers/ColoredConsolePrinter.cs View File

@ -4,25 +4,24 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IllusionPlugin.Logging;
using LoggerBase = IllusionPlugin.Logging.Logger;
using IPA.Logging;
namespace IllusionInjector.Logging.Printers
namespace IPA.Logging.Printers
{
public class ColoredConsolePrinter : LogPrinter
{
LoggerBase.LogLevel filter = LoggerBase.LogLevel.All;
public override LoggerBase.LogLevel Filter { get => filter; set => filter = value; }
Logger.LogLevel filter = Logger.LogLevel.All;
public override Logger.LogLevel Filter { get => filter; set => filter = value; }
ConsoleColor color = Console.ForegroundColor;
public ConsoleColor Color { get => color; set => color = value; }
public override void Print(LoggerBase.Level level, DateTime time, string logName, string message)
public override void Print(Logger.Level level, DateTime time, string logName, string message)
{
if (((byte)level & (byte)StandardLogger.PrintFilter) == 0) return;
Console.ForegroundColor = color;
foreach (var line in message.Split(new string[] { "\n", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
Console.WriteLine(string.Format(LoggerBase.LogFormat, line, logName, time, level.ToString().ToUpper()));
Console.WriteLine(string.Format(Logger.LogFormat, line, logName, time, level.ToString().ToUpper()));
Console.ResetColor();
}
}

IPA.Loader/IllusionInjector/Logging/Printers/GZFilePrinter.cs → IPA.Loader/Logging/Printers/GZFilePrinter.cs View File

@ -1,4 +1,4 @@
using IllusionPlugin.Logging;
using IPA.Logging;
using Ionic.Zlib;
using System;
using System.Collections.Generic;
@ -8,7 +8,7 @@ using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace IllusionInjector.Logging.Printers
namespace IPA.Logging.Printers
{
public abstract class GZFilePrinter : LogPrinter
{

IPA.Loader/IllusionInjector/Logging/Printers/GlobalLogFilePrinter.cs → IPA.Loader/Logging/Printers/GlobalLogFilePrinter.cs View File

@ -4,19 +4,18 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IllusionPlugin.Logging;
using LoggerBase = IllusionPlugin.Logging.Logger;
using IPA.Logging;
namespace IllusionInjector.Logging.Printers
namespace IPA.Logging.Printers
{
class GlobalLogFilePrinter : GZFilePrinter
{
public override LoggerBase.LogLevel Filter { get; set; } = LoggerBase.LogLevel.All;
public override Logger.LogLevel Filter { get; set; } = Logger.LogLevel.All;
public override void Print(IllusionPlugin.Logging.Logger.Level level, DateTime time, string logName, string message)
public override void Print(IPA.Logging.Logger.Level level, DateTime time, string logName, string message)
{
foreach (var line in message.Split(new string[] { "\n", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
fileWriter.WriteLine(string.Format(LoggerBase.LogFormat, line, logName, time, level.ToString().ToUpper()));
fileWriter.WriteLine(string.Format(Logger.LogFormat, line, logName, time, level.ToString().ToUpper()));
}
protected override FileInfo GetFileInfo()

IPA.Loader/IllusionInjector/Logging/Printers/PluginLogFilePrinter.cs → IPA.Loader/Logging/Printers/PluginLogFilePrinter.cs View File

@ -1,17 +1,16 @@
using IllusionPlugin.Logging;
using IPA.Logging;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LoggerBase = IllusionPlugin.Logging.Logger;
namespace IllusionInjector.Logging.Printers
namespace IPA.Logging.Printers
{
class PluginLogFilePrinter : GZFilePrinter
{
public override LoggerBase.LogLevel Filter { get; set; } = LoggerBase.LogLevel.All;
public override Logger.LogLevel Filter { get; set; } = Logger.LogLevel.All;
private string name;
@ -28,7 +27,7 @@ namespace IllusionInjector.Logging.Printers
this.name = name;
}
public override void Print(IllusionPlugin.Logging.Logger.Level level, DateTime time, string logName, string message)
public override void Print(IPA.Logging.Logger.Level level, DateTime time, string logName, string message)
{
foreach (var line in message.Split(new string[] { "\n", Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
fileWriter.WriteLine(string.Format("[{3} @ {2:HH:mm:ss}] {0}", line, logName, time, level.ToString().ToUpper()));

IPA.Loader/IllusionInjector/Logging/StandardLogger.cs → IPA.Loader/Logging/StandardLogger.cs View File

@ -1,6 +1,4 @@
using IllusionInjector.Logging.Printers;
using IllusionPlugin;
using IllusionPlugin.Logging;
using IPA.Logging;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
@ -10,25 +8,11 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using IPA;
using LoggerBase = IllusionPlugin.Logging.Logger;
using LoggerBase = IPA.Logging.Logger;
using IPA.Logging.Printers;
namespace IllusionInjector.Logging
namespace IPA.Logging
{
internal static class Logger
{
private static LoggerBase _log;
internal static LoggerBase log
{
get
{
if (_log == null)
_log = new StandardLogger("IPA");
return _log;
}
}
internal static bool LogCreated => _log != null;
}
public class StandardLogger : LoggerBase
{
private static readonly IReadOnlyList<LogPrinter> defaultPrinters = new List<LogPrinter>()

+ 33
- 0
IPA.Loader/Logging/UnityLogInterceptor.cs View File

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
namespace IPA.Logging
{
internal class UnityLogInterceptor
{
public static Logger UnityLogger = new StandardLogger("UnityEngine");
public static Logger.Level LogTypeToLevel(LogType type)
{
switch (type)
{
case LogType.Assert:
return Logger.Level.Debug;
case LogType.Error:
return Logger.Level.Error;
case LogType.Exception:
return Logger.Level.Critical;
case LogType.Log:
return Logger.Level.Info;
case LogType.Warning:
return Logger.Level.Warning;
default:
return Logger.Level.Info;
}
}
}
}

Loading…
Cancel
Save