Improved logging (#103)
This commit is contained in:
parent
4e24866b47
commit
a8ba340dde
57 changed files with 555 additions and 870 deletions
117
Ryujinx/Config.cs
Normal file
117
Ryujinx/Config.cs
Normal file
|
@ -0,0 +1,117 @@
|
|||
using Ryujinx.Core.Input;
|
||||
using Ryujinx.Core.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Ryujinx
|
||||
{
|
||||
public static class Config
|
||||
{
|
||||
public static JoyCon FakeJoyCon { get; private set; }
|
||||
|
||||
public static void Read(Logger Log)
|
||||
{
|
||||
string IniFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
|
||||
|
||||
string IniPath = Path.Combine(IniFolder, "Ryujinx.conf");
|
||||
|
||||
IniParser Parser = new IniParser(IniPath);
|
||||
|
||||
AOptimizations.DisableMemoryChecks = !Convert.ToBoolean(Parser.Value("Enable_Memory_Checks"));
|
||||
|
||||
Console.WriteLine(Parser.Value("Logging_Enable_Warn"));
|
||||
|
||||
bool LoggingEnableDebug = Convert.ToBoolean(Parser.Value("Logging_Enable_Debug"));
|
||||
bool LoggingEnableStub = Convert.ToBoolean(Parser.Value("Logging_Enable_Stub"));
|
||||
bool LoggingEnableInfo = Convert.ToBoolean(Parser.Value("Logging_Enable_Info"));
|
||||
bool LoggingEnableTrace = Convert.ToBoolean(Parser.Value("Logging_Enable_Trace"));
|
||||
bool LoggingEnableWarn = Convert.ToBoolean(Parser.Value("Logging_Enable_Warn"));
|
||||
bool LoggingEnableError = Convert.ToBoolean(Parser.Value("Logging_Enable_Error"));
|
||||
|
||||
string[] FilteredLogClasses = Parser.Value("Logging_Filtered_Classes").Split(',', StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
//When the classes are specified on the list, we only
|
||||
//enable the classes that are on the list.
|
||||
//So, first disable everything, then enable
|
||||
//the classes that the user added to the list.
|
||||
if (FilteredLogClasses.Length > 0)
|
||||
{
|
||||
foreach (LogClass Class in Enum.GetValues(typeof(LogClass)))
|
||||
{
|
||||
Log.SetEnable(Class, false);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (string LogClass in FilteredLogClasses)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(LogClass.Trim()))
|
||||
{
|
||||
foreach (LogClass Class in Enum.GetValues(typeof(LogClass)))
|
||||
{
|
||||
if (Class.ToString().ToLower().Contains(LogClass.Trim().ToLower()))
|
||||
{
|
||||
Log.SetEnable(Class, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FakeJoyCon = new JoyCon
|
||||
{
|
||||
Left = new JoyConLeft
|
||||
{
|
||||
StickUp = Convert.ToInt16(Parser.Value("Controls_Left_FakeJoycon_Stick_Up")),
|
||||
StickDown = Convert.ToInt16(Parser.Value("Controls_Left_FakeJoycon_Stick_Down")),
|
||||
StickLeft = Convert.ToInt16(Parser.Value("Controls_Left_FakeJoycon_Stick_Left")),
|
||||
StickRight = Convert.ToInt16(Parser.Value("Controls_Left_FakeJoycon_Stick_Right")),
|
||||
StickButton = Convert.ToInt16(Parser.Value("Controls_Left_FakeJoycon_Stick_Button")),
|
||||
DPadUp = Convert.ToInt16(Parser.Value("Controls_Left_FakeJoycon_DPad_Up")),
|
||||
DPadDown = Convert.ToInt16(Parser.Value("Controls_Left_FakeJoycon_DPad_Down")),
|
||||
DPadLeft = Convert.ToInt16(Parser.Value("Controls_Left_FakeJoycon_DPad_Left")),
|
||||
DPadRight = Convert.ToInt16(Parser.Value("Controls_Left_FakeJoycon_DPad_Right")),
|
||||
ButtonMinus = Convert.ToInt16(Parser.Value("Controls_Left_FakeJoycon_Button_Minus")),
|
||||
ButtonL = Convert.ToInt16(Parser.Value("Controls_Left_FakeJoycon_Button_L")),
|
||||
ButtonZL = Convert.ToInt16(Parser.Value("Controls_Left_FakeJoycon_Button_ZL"))
|
||||
},
|
||||
|
||||
Right = new JoyConRight
|
||||
{
|
||||
StickUp = Convert.ToInt16(Parser.Value("Controls_Right_FakeJoycon_Stick_Up")),
|
||||
StickDown = Convert.ToInt16(Parser.Value("Controls_Right_FakeJoycon_Stick_Down")),
|
||||
StickLeft = Convert.ToInt16(Parser.Value("Controls_Right_FakeJoycon_Stick_Left")),
|
||||
StickRight = Convert.ToInt16(Parser.Value("Controls_Right_FakeJoycon_Stick_Right")),
|
||||
StickButton = Convert.ToInt16(Parser.Value("Controls_Right_FakeJoycon_Stick_Button")),
|
||||
ButtonA = Convert.ToInt16(Parser.Value("Controls_Right_FakeJoycon_Button_A")),
|
||||
ButtonB = Convert.ToInt16(Parser.Value("Controls_Right_FakeJoycon_Button_B")),
|
||||
ButtonX = Convert.ToInt16(Parser.Value("Controls_Right_FakeJoycon_Button_X")),
|
||||
ButtonY = Convert.ToInt16(Parser.Value("Controls_Right_FakeJoycon_Button_Y")),
|
||||
ButtonPlus = Convert.ToInt16(Parser.Value("Controls_Right_FakeJoycon_Button_Plus")),
|
||||
ButtonR = Convert.ToInt16(Parser.Value("Controls_Right_FakeJoycon_Button_R")),
|
||||
ButtonZR = Convert.ToInt16(Parser.Value("Controls_Right_FakeJoycon_Button_ZR"))
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/a/37772571
|
||||
public class IniParser
|
||||
{
|
||||
private readonly Dictionary<string, string> Values;
|
||||
|
||||
public IniParser(string Path)
|
||||
{
|
||||
Values = File.ReadLines(Path)
|
||||
.Where(Line => !string.IsNullOrWhiteSpace(Line) && !Line.StartsWith('#'))
|
||||
.Select(Line => Line.Split('=', 2))
|
||||
.ToDictionary(Parts => Parts[0].Trim(), Parts => Parts.Length > 1 ? Parts[1].Trim() : null);
|
||||
}
|
||||
|
||||
public string Value(string Name)
|
||||
{
|
||||
return Values.TryGetValue(Name, out string Value) ? Value : null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,39 +1,24 @@
|
|||
#Enable cpu memory checks (slow)
|
||||
Enable_Memory_Checks = false
|
||||
|
||||
#Enable print informations logs
|
||||
Logging_Enable_Info = true
|
||||
|
||||
#Enable print trace logs
|
||||
Logging_Enable_Trace = false
|
||||
|
||||
#Enable print debug logs
|
||||
Logging_Enable_Debug = false
|
||||
|
||||
#Enable print stubbed calls logs
|
||||
Logging_Enable_Stub = true
|
||||
|
||||
#Enable print informations logs
|
||||
Logging_Enable_Info = true
|
||||
|
||||
#Enable print warning logs
|
||||
Logging_Enable_Warn = true
|
||||
|
||||
#Enable print error logs
|
||||
Logging_Enable_Error = true
|
||||
|
||||
#Enable print fatal logs
|
||||
Logging_Enable_Fatal = true
|
||||
|
||||
#Enable print stubbed calls logs
|
||||
Logging_Enable_Stub = false
|
||||
|
||||
#Enable print Ipc logs
|
||||
Logging_Enable_Ipc = false
|
||||
|
||||
#Enable log filter
|
||||
Logging_Enable_Filter = false
|
||||
|
||||
#Filtered log classes, seperated by ',', eg. `Logging_Filtered_Classes = Loader,ServiceFS`
|
||||
#Filtered log classes, seperated by ", ", eg. `Logging_Filtered_Classes = Loader, ServiceFS`
|
||||
Logging_Filtered_Classes =
|
||||
|
||||
#Save logs into Ryujinx.log
|
||||
Logging_Enable_LogFile = false
|
||||
|
||||
#https://github.com/opentk/opentk/blob/develop/src/OpenTK/Input/Key.cs
|
||||
Controls_Left_FakeJoycon_Stick_Up = 105
|
||||
Controls_Left_FakeJoycon_Stick_Down = 101
|
||||
|
@ -59,4 +44,4 @@ Controls_Right_FakeJoycon_Button_X = 85
|
|||
Controls_Right_FakeJoycon_Button_Y = 104
|
||||
Controls_Right_FakeJoycon_Button_Plus = 121
|
||||
Controls_Right_FakeJoycon_Button_R = 103
|
||||
Controls_Right_FakeJoycon_Button_ZR = 97
|
||||
Controls_Right_FakeJoycon_Button_ZR = 97
|
51
Ryujinx/Ui/ConsoleLog.cs
Normal file
51
Ryujinx/Ui/ConsoleLog.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue