Browse Source

Fixed the logger because testing is for nubs

refactor
Anairkoen Schno 6 years ago
parent
commit
67f80b0653
10 changed files with 66 additions and 33 deletions
  1. +1
    -1
      IllusionInjector/BeatSaber/CompositeBSPlugin.cs
  2. +3
    -3
      IllusionInjector/Bootstrapper.cs
  3. +4
    -4
      IllusionInjector/IllusionInjector.csproj
  4. +21
    -12
      IllusionInjector/Logging/Printers/GlobalZFIlePrinter.cs
  5. +4
    -2
      IllusionInjector/Logging/Printers/PluginLogFilePrinter.cs
  6. +25
    -8
      IllusionInjector/Logging/StandardLogger.cs
  7. +5
    -0
      IllusionInjector/PluginManager.cs
  8. +1
    -1
      IllusionInjector/obj/Debug/IllusionInjector.csproj.CoreCompileInputs.cache
  9. +1
    -1
      IllusionInjector/packages.config
  10. +1
    -1
      IllusionPlugin/BeatSaber/IBeatSaberPlugin.cs

+ 1
- 1
IllusionInjector/BeatSaber/CompositeBSPlugin.cs View File

@ -82,7 +82,7 @@ namespace IllusionInjector {
get { throw new NotImplementedException(); }
}
public string Version {
public Version Version {
get { throw new NotImplementedException(); }
}


+ 3
- 3
IllusionInjector/Bootstrapper.cs View File

@ -13,10 +13,10 @@ namespace IllusionInjector
void Awake()
{
if (Environment.CommandLine.Contains("--verbose") && !Screen.fullScreen)
{
//if (Environment.CommandLine.Contains("--verbose"))
//{
Windows.GuiConsole.CreateConsole();
}
//}
Application.logMessageReceived += delegate (string condition, string stackTrace, LogType type)
{


+ 4
- 4
IllusionInjector/IllusionInjector.csproj View File

@ -34,6 +34,9 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Ionic.Zlib, Version=1.9.1.5, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c, processorArchitecture=MSIL">
<HintPath>..\packages\Ionic.Zlib.1.9.1.5\lib\Ionic.Zlib.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
@ -45,9 +48,6 @@
<HintPath>..\Libs\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="zlib.net, Version=1.0.3.0, Culture=neutral, PublicKeyToken=47d7877cb3620160">
<HintPath>..\packages\zlib.net.1.0.4.0\lib\zlib.net.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Bootstrapper.cs" />
@ -56,7 +56,7 @@
<Compile Include="Injector.cs" />
<Compile Include="IPA\CompositeIPAPlugin.cs" />
<Compile Include="Logging\Printers\ColoredConsolePrinter.cs" />
<Compile Include="Logging\Printers\GlobalZFIlePrinter.cs" />
<Compile Include="Logging\Printers\GlobalZFilePrinter.cs" />
<Compile Include="Logging\Printers\PluginLogFilePrinter.cs" />
<Compile Include="Logging\StandardLogger.cs" />
<Compile Include="Logging\UnityLogInterceptor.cs" />


+ 21
- 12
IllusionInjector/Logging/Printers/GlobalZFIlePrinter.cs View File

@ -1,44 +1,45 @@
using IllusionPlugin.Logging;
using Ionic.Zlib;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using zlib;
namespace IllusionInjector.Logging.Printers
{
public class GlobalZFIlePrinter : LogPrinter
public class GlobalZFilePrinter : LogPrinter
{
public override IllusionPlugin.Logging.Logger.LogLevel Filter { get; set; }
public override IllusionPlugin.Logging.Logger.LogLevel Filter { get; set; } = IllusionPlugin.Logging.Logger.LogLevel.All;
private FileInfo fileInfo;
private StreamWriter fileWriter;
private GZipStream zstream;
private FileStream fstream;
private static FileInfo GetFileInfo()
{
var logsDir = new DirectoryInfo("Logs");
logsDir.Create();
var finfo = new FileInfo(Path.Combine(logsDir.FullName, $"{DateTime.Now:YYYY.MM.DD.HH.MM}.log.z"));
var finfo = new FileInfo(Path.Combine(logsDir.FullName, $"{DateTime.Now:yyyy.MM.dd.HH.MM}.log.z"));
finfo.Create().Close();
return finfo;
}
public GlobalZFIlePrinter()
public GlobalZFilePrinter()
{
fileInfo = GetFileInfo();
}
public override void StartPrint()
{
fileWriter = new StreamWriter(
new ZOutputStream(fileInfo.Open(FileMode.Append, FileAccess.Write, FileShare.Read))
{
FlushMode = zlibConst.Z_FULL_FLUSH
},
Encoding.UTF8
);
fstream = fileInfo.Open(FileMode.Append, FileAccess.Write);
zstream = new GZipStream(fstream, CompressionMode.Compress)
{
FlushMode = FlushType.Full
};
fileWriter = new StreamWriter(zstream, Encoding.UTF8);
}
public override void Print(IllusionPlugin.Logging.Logger.Level level, DateTime time, string logName, string message)
@ -49,7 +50,15 @@ namespace IllusionInjector.Logging.Printers
public override void EndPrint()
{
fileWriter.Flush();
zstream.Flush();
fstream.Flush();
fileWriter.Close();
zstream.Close();
fstream.Close();
fileWriter.Dispose();
zstream.Dispose();
fstream.Dispose();
}
}
}

+ 4
- 2
IllusionInjector/Logging/Printers/PluginLogFilePrinter.cs View File

@ -10,7 +10,7 @@ namespace IllusionInjector.Logging.Printers
{
public class PluginLogFilePrinter : LogPrinter
{
public override IllusionPlugin.Logging.Logger.LogLevel Filter { get; set; }
public override IllusionPlugin.Logging.Logger.LogLevel Filter { get; set; } = IllusionPlugin.Logging.Logger.LogLevel.All;
private FileInfo fileInfo;
private StreamWriter fileWriter;
@ -19,7 +19,7 @@ namespace IllusionInjector.Logging.Printers
{
var logsDir = new DirectoryInfo(Path.Combine("Logs",modName));
logsDir.Create();
var finfo = new FileInfo(Path.Combine(logsDir.FullName, $"{DateTime.Now:YYYY.MM.DD.HH.MM}.log"));
var finfo = new FileInfo(Path.Combine(logsDir.FullName, $"{DateTime.Now:yyyy.MM.dd.HH.MM}.log"));
finfo.CreateText().Close();
return finfo;
}
@ -42,6 +42,8 @@ namespace IllusionInjector.Logging.Printers
public override void EndPrint()
{
fileWriter.Flush();
fileWriter.Close();
fileWriter.Dispose();
}
}


+ 25
- 8
IllusionInjector/Logging/StandardLogger.cs View File

@ -55,7 +55,7 @@ namespace IllusionInjector.Logging
Filter = LogLevel.CriticalOnly,
Color = ConsoleColor.Magenta,
},
new GlobalZFIlePrinter()
new GlobalZFilePrinter()
};
private string logName;
@ -104,22 +104,39 @@ namespace IllusionInjector.Logging
while (_logQueue.TryTake(out LogMessage msg, Timeout.Infinite)) {
foreach (var printer in msg.logger.printers)
{
if (((byte)msg.level & (byte)printer.Filter) != 0)
try
{
if (!started.Contains(printer))
if (((byte)msg.level & (byte)printer.Filter) != 0)
{
printer.StartPrint();
started.Add(printer);
}
if (!started.Contains(printer))
{
printer.StartPrint();
started.Add(printer);
}
printer.Print(msg.level, msg.time, msg.logger.logName, msg.message);
printer.Print(msg.level, msg.time, msg.logger.logName, msg.message);
}
}
catch (Exception e)
{
Console.WriteLine($"printer errored {e}");
}
}
if (_logQueue.Count == 0)
{
foreach (var printer in started)
printer.EndPrint();
{
try
{
printer.EndPrint();
}
catch (Exception e)
{
Console.WriteLine($"printer errored {e}");
}
}
started.Clear();
}
}


+ 5
- 0
IllusionInjector/PluginManager.cs View File

@ -101,6 +101,11 @@ namespace IllusionInjector
Logger.log.Info($"{plugin.Name}: {plugin.Version}");
}
Logger.log.Info("-----------------------------");
foreach (var plugin in _ipaPlugins)
{
Logger.log.Info($"{plugin.Name}: {plugin.Version}");
}
Logger.log.Info("-----------------------------");
}
private static Tuple<IEnumerable<IBeatSaberPlugin>, IEnumerable<IPlugin>> LoadPluginsFromFile(string file, string exeName)


+ 1
- 1
IllusionInjector/obj/Debug/IllusionInjector.csproj.CoreCompileInputs.cache View File

@ -1 +1 @@
8c1883c8697a3dc7189ee9ff1c9d85d453a46fe5
479f561c6be8784a5830081167b62f103b95e138

+ 1
- 1
IllusionInjector/packages.config View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="zlib.net" version="1.0.4.0" targetFramework="net46" />
<package id="Ionic.Zlib" version="1.9.1.5" targetFramework="net46" />
</packages>

+ 1
- 1
IllusionPlugin/BeatSaber/IBeatSaberPlugin.cs View File

@ -20,7 +20,7 @@ namespace IllusionPlugin
/// <summary>
/// Gets the version of the plugin.
/// </summary>
string Version { get; }
Version Version { get; }
/// <summary>
/// Gets invoked when the application is started.


Loading…
Cancel
Save