Improved logging (#103)

This commit is contained in:
gdkchan 2018-04-24 15:57:39 -03:00 committed by GitHub
parent 456da77838
commit ae8bb487db
57 changed files with 555 additions and 870 deletions

51
Ryujinx/Ui/ConsoleLog.cs Normal file
View file

@ -0,0 +1,51 @@
using Ryujinx.Core.Logging;
using System;
using System.Collections.Generic;
using System.Threading;
namespace Ryujinx
{
static class ConsoleLog
{
private static Dictionary<LogLevel, ConsoleColor> LogColors;
private static object ConsoleLock;
static ConsoleLog()
{
LogColors = new Dictionary<LogLevel, ConsoleColor>()
{
{ LogLevel.Stub, ConsoleColor.DarkGray },
{ LogLevel.Info, ConsoleColor.White },
{ LogLevel.Warning, ConsoleColor.Yellow },
{ LogLevel.Error, ConsoleColor.Red }
};
ConsoleLock = new object();
}
public static void PrintLog(object sender, LogEventArgs e)
{
string FormattedTime = e.Time.ToString(@"hh\:mm\:ss\.fff");
string CurrentThread = Thread.CurrentThread.ManagedThreadId.ToString("d4");
string Message = FormattedTime + " | " + CurrentThread + " " + e.Message;
if (LogColors.TryGetValue(e.Level, out ConsoleColor Color))
{
lock (ConsoleLock)
{
Console.ForegroundColor = Color;
Console.WriteLine(Message);
Console.ResetColor();
}
}
else
{
Console.WriteLine(Message);
}
}
}
}

View file

@ -12,10 +12,6 @@ namespace Ryujinx
{
static void Main(string[] args)
{
Config.Read();
AOptimizations.DisableMemoryChecks = !Config.EnableMemoryChecks;
Console.Title = "Ryujinx Console";
IGalRenderer Renderer = new OpenGLRenderer();
@ -24,6 +20,10 @@ namespace Ryujinx
Switch Ns = new Switch(Renderer, AudioOut);
Config.Read(Ns.Log);
Ns.Log.Updated += ConsoleLog.PrintLog;
if (args.Length == 1)
{
if (Directory.Exists(args[0]))
@ -37,27 +37,27 @@ namespace Ryujinx
if (RomFsFiles.Length > 0)
{
Logging.Info(LogClass.Loader, "Loading as cart with RomFS.");
Console.WriteLine("Loading as cart with RomFS.");
Ns.LoadCart(args[0], RomFsFiles[0]);
}
else
{
Logging.Info(LogClass.Loader, "Loading as cart WITHOUT RomFS.");
Console.WriteLine("Loading as cart WITHOUT RomFS.");
Ns.LoadCart(args[0]);
}
}
else if (File.Exists(args[0]))
{
Logging.Info(LogClass.Loader, "Loading as homebrew.");
Console.WriteLine("Loading as homebrew.");
Ns.LoadProgram(args[0]);
}
}
else
{
Logging.Error(LogClass.Loader, "Please specify the folder with the NSOs/IStorage or a NSO/NRO.");
Console.WriteLine("Please specify the folder with the NSOs/IStorage or a NSO/NRO.");
}
using (GLScreen Screen = new GLScreen(Ns, Renderer))