2018-02-09 00:43:22 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx
|
|
|
|
|
{
|
|
|
|
|
public static class Logging
|
|
|
|
|
{
|
|
|
|
|
private static Stopwatch ExecutionTime = new Stopwatch();
|
2018-02-20 10:54:00 +00:00
|
|
|
|
private const string LogFileName = "Ryujinx.log";
|
2018-02-09 00:43:22 +00:00
|
|
|
|
|
2018-02-09 02:47:32 +00:00
|
|
|
|
public static bool EnableInfo = Config.LoggingEnableInfo;
|
|
|
|
|
public static bool EnableTrace = Config.LoggingEnableTrace;
|
|
|
|
|
public static bool EnableDebug = Config.LoggingEnableDebug;
|
|
|
|
|
public static bool EnableWarn = Config.LoggingEnableWarn;
|
|
|
|
|
public static bool EnableError = Config.LoggingEnableError;
|
|
|
|
|
public static bool EnableFatal = Config.LoggingEnableFatal;
|
|
|
|
|
public static bool EnableLogFile = Config.LoggingEnableLogFile;
|
2018-02-09 00:43:22 +00:00
|
|
|
|
|
|
|
|
|
static Logging()
|
|
|
|
|
{
|
|
|
|
|
ExecutionTime.Start();
|
|
|
|
|
|
|
|
|
|
if (File.Exists(LogFileName)) File.Delete(LogFileName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetExecutionTime()
|
|
|
|
|
{
|
|
|
|
|
return ExecutionTime.ElapsedMilliseconds.ToString().PadLeft(8, '0') + "ms";
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-09 19:39:50 +00:00
|
|
|
|
private static string WhoCalledMe()
|
|
|
|
|
{
|
|
|
|
|
return new StackTrace().GetFrame(2).GetMethod().Name;
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-09 00:43:22 +00:00
|
|
|
|
private static void LogFile(string Message)
|
|
|
|
|
{
|
|
|
|
|
if (EnableLogFile)
|
|
|
|
|
{
|
|
|
|
|
using (StreamWriter Writer = File.AppendText(LogFileName))
|
|
|
|
|
{
|
|
|
|
|
Writer.WriteLine(Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Info(string Message)
|
|
|
|
|
{
|
|
|
|
|
if (EnableInfo)
|
|
|
|
|
{
|
|
|
|
|
string Text = $"{GetExecutionTime()} | INFO > {Message}";
|
|
|
|
|
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.White;
|
|
|
|
|
Console.WriteLine(Text.PadLeft(Text.Length + 1, ' '));
|
|
|
|
|
Console.ResetColor();
|
|
|
|
|
|
|
|
|
|
LogFile(Text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Trace(string Message)
|
|
|
|
|
{
|
|
|
|
|
if (EnableTrace)
|
|
|
|
|
{
|
2018-02-09 19:39:50 +00:00
|
|
|
|
string Text = $"{GetExecutionTime()} | TRACE > {WhoCalledMe()} - {Message}";
|
2018-02-09 00:43:22 +00:00
|
|
|
|
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.DarkGray;
|
|
|
|
|
Console.WriteLine(Text.PadLeft(Text.Length + 1, ' '));
|
|
|
|
|
Console.ResetColor();
|
|
|
|
|
|
|
|
|
|
LogFile(Text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Debug(string Message)
|
|
|
|
|
{
|
|
|
|
|
if (EnableDebug)
|
|
|
|
|
{
|
2018-02-09 19:39:50 +00:00
|
|
|
|
string Text = $"{GetExecutionTime()} | DEBUG > {WhoCalledMe()} - {Message}";
|
2018-02-09 00:43:22 +00:00
|
|
|
|
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.Gray;
|
|
|
|
|
Console.WriteLine(Text.PadLeft(Text.Length + 1, ' '));
|
|
|
|
|
Console.ResetColor();
|
|
|
|
|
|
|
|
|
|
LogFile(Text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Warn(string Message)
|
|
|
|
|
{
|
|
|
|
|
if (EnableWarn)
|
|
|
|
|
{
|
2018-02-09 19:39:50 +00:00
|
|
|
|
string Text = $"{GetExecutionTime()} | WARN > {WhoCalledMe()} - {Message}";
|
2018-02-09 00:43:22 +00:00
|
|
|
|
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
|
|
|
|
Console.WriteLine(Text.PadLeft(Text.Length + 1, ' '));
|
|
|
|
|
Console.ResetColor();
|
|
|
|
|
|
|
|
|
|
LogFile(Text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Error(string Message)
|
|
|
|
|
{
|
|
|
|
|
if (EnableError)
|
|
|
|
|
{
|
2018-02-09 19:39:50 +00:00
|
|
|
|
string Text = $"{GetExecutionTime()} | ERROR > {WhoCalledMe()} - {Message}";
|
2018-02-09 00:43:22 +00:00
|
|
|
|
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.Red;
|
|
|
|
|
Console.WriteLine(Text.PadLeft(Text.Length + 1, ' '));
|
|
|
|
|
Console.ResetColor();
|
|
|
|
|
|
|
|
|
|
LogFile(Text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Fatal(string Message)
|
|
|
|
|
{
|
|
|
|
|
if (EnableFatal)
|
|
|
|
|
{
|
2018-02-09 19:39:50 +00:00
|
|
|
|
string Text = $"{GetExecutionTime()} | FATAL > {WhoCalledMe()} - {Message}";
|
2018-02-09 00:43:22 +00:00
|
|
|
|
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.Magenta;
|
|
|
|
|
Console.WriteLine(Text.PadLeft(Text.Length + 1, ' '));
|
|
|
|
|
Console.ResetColor();
|
|
|
|
|
|
|
|
|
|
LogFile(Text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|