1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-12-29 17:46:02 +00:00

log calling method in logs (#71)

This commit is contained in:
emmauss 2018-04-08 23:30:50 +03:00 committed by gdkchan
parent 36dfd20c87
commit b2668e659c
2 changed files with 130 additions and 64 deletions

View file

@ -2,6 +2,7 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Runtime.CompilerServices;
using System.Text; using System.Text;
namespace Ryujinx.Core namespace Ryujinx.Core
@ -21,6 +22,16 @@ namespace Ryujinx.Core
private static bool EnableIpc = Config.LoggingEnableIpc; private static bool EnableIpc = Config.LoggingEnableIpc;
private static bool EnableLogFile = Config.LoggingEnableLogFile; private static bool EnableLogFile = Config.LoggingEnableLogFile;
private enum LogLevel
{
Debug = 1,
Error = 2,
Fatal = 3,
Info = 4,
Trace = 5,
Warn = 6
}
static Logging() static Logging()
{ {
if (File.Exists(LogFileName)) File.Delete(LogFileName); if (File.Exists(LogFileName)) File.Delete(LogFileName);
@ -30,14 +41,42 @@ namespace Ryujinx.Core
ExecutionTime.Start(); ExecutionTime.Start();
} }
public static string GetExecutionTime() public static string GetExecutionTime() => ExecutionTime.ElapsedMilliseconds.ToString().PadLeft(8, '0') + "ms";
private static void LogMessage(LogEntry LogEntry)
{ {
return ExecutionTime.ElapsedMilliseconds.ToString().PadLeft(8, '0') + "ms"; ConsoleColor consoleColor = ConsoleColor.White;
switch (LogEntry.LogLevel)
{
case LogLevel.Debug:
consoleColor = ConsoleColor.Gray;
break;
case LogLevel.Error:
consoleColor = ConsoleColor.Red;
break;
case LogLevel.Fatal:
consoleColor = ConsoleColor.Magenta;
break;
case LogLevel.Info:
consoleColor = ConsoleColor.White;
break;
case LogLevel.Trace:
consoleColor = ConsoleColor.DarkGray;
break;
case LogLevel.Warn:
consoleColor = ConsoleColor.Yellow;
break;
} }
private static string WhoCalledMe() string Text = $"{LogEntry.ExecutionTime} | {LogEntry.LogLevel.ToString()} > " +
{ $"{LogEntry.CallingMember}:{LogEntry.CallingLineNumber} > {LogEntry.Message}";
return new StackTrace().GetFrame(2).GetMethod().Name;
Console.ForegroundColor = consoleColor;
Console.WriteLine(Text.PadLeft(Text.Length + 1, ' '));
Console.ResetColor();
LogFile(Text);
} }
private static void LogFile(string Message) private static void LogFile(string Message)
@ -51,87 +90,105 @@ namespace Ryujinx.Core
} }
} }
public static void Info(string Message) public static void Info(string Message,
[CallerMemberName] string CallingMember = "",
[CallerLineNumber] int CallingLineNumber = 0)
{ {
if (EnableInfo) if (EnableInfo)
{ {
string Text = $"{GetExecutionTime()} | INFO > {Message}"; LogMessage(new LogEntry
{
Console.ForegroundColor = ConsoleColor.White; CallingLineNumber = CallingLineNumber,
Console.WriteLine(Text.PadLeft(Text.Length + 1, ' ')); CallingMember = CallingMember,
Console.ResetColor(); LogLevel = LogLevel.Info,
Message = Message,
LogFile(Text); ExecutionTime = GetExecutionTime()
});
} }
} }
public static void Trace(string Message) public static void Trace(string Message,
[CallerMemberName] string CallingMember = "",
[CallerLineNumber] int CallingLineNumber = 0)
{ {
if (EnableTrace) if (EnableTrace)
{ {
string Text = $"{GetExecutionTime()} | TRACE > {WhoCalledMe()} - {Message}"; LogMessage(new LogEntry
{
Console.ForegroundColor = ConsoleColor.DarkGray; CallingLineNumber = CallingLineNumber,
Console.WriteLine(Text.PadLeft(Text.Length + 1, ' ')); CallingMember = CallingMember,
Console.ResetColor(); LogLevel = LogLevel.Trace,
Message = Message,
LogFile(Text); ExecutionTime = GetExecutionTime()
});
} }
} }
public static void Debug(string Message) public static void Debug(string Message,
[CallerMemberName] string CallingMember = "",
[CallerLineNumber] int CallingLineNumber = 0)
{ {
if (EnableDebug) if (EnableDebug)
{ {
string Text = $"{GetExecutionTime()} | DEBUG > {WhoCalledMe()} - {Message}"; LogMessage(new LogEntry
{
Console.ForegroundColor = ConsoleColor.Gray; CallingLineNumber = CallingLineNumber,
Console.WriteLine(Text.PadLeft(Text.Length + 1, ' ')); CallingMember = CallingMember,
Console.ResetColor(); LogLevel = LogLevel.Debug,
Message = Message,
LogFile(Text); ExecutionTime = GetExecutionTime()
});
} }
} }
public static void Warn(string Message) public static void Warn(string Message,
[CallerMemberName] string CallingMember = "",
[CallerLineNumber] int CallingLineNumber = 0)
{ {
if (EnableWarn) if (EnableWarn)
{ {
string Text = $"{GetExecutionTime()} | WARN > {WhoCalledMe()} - {Message}"; LogMessage(new LogEntry
{
Console.ForegroundColor = ConsoleColor.Yellow; CallingLineNumber = CallingLineNumber,
Console.WriteLine(Text.PadLeft(Text.Length + 1, ' ')); CallingMember = CallingMember,
Console.ResetColor(); LogLevel = LogLevel.Warn,
Message = Message,
LogFile(Text); ExecutionTime = GetExecutionTime()
});
} }
} }
public static void Error(string Message) public static void Error(string Message,
[CallerMemberName] string CallingMember = "",
[CallerLineNumber] int CallingLineNumber = 0)
{ {
if (EnableError) if (EnableError)
{ {
string Text = $"{GetExecutionTime()} | ERROR > {WhoCalledMe()} - {Message}"; LogMessage(new LogEntry
{
Console.ForegroundColor = ConsoleColor.Red; CallingLineNumber = CallingLineNumber,
Console.WriteLine(Text.PadLeft(Text.Length + 1, ' ')); CallingMember = CallingMember,
Console.ResetColor(); LogLevel = LogLevel.Error,
Message = Message,
LogFile(Text); ExecutionTime = GetExecutionTime()
});
} }
} }
public static void Fatal(string Message) public static void Fatal(string Message,
[CallerMemberName] string CallingMember = "",
[CallerLineNumber] int CallingLineNumber = 0)
{ {
if (EnableFatal) if (EnableFatal)
{ {
string Text = $"{GetExecutionTime()} | FATAL > {WhoCalledMe()} - {Message}"; LogMessage(new LogEntry
{
Console.ForegroundColor = ConsoleColor.Magenta; CallingLineNumber = CallingLineNumber,
Console.WriteLine(Text.PadLeft(Text.Length + 1, ' ')); CallingMember = CallingMember,
Console.ResetColor(); LogLevel = LogLevel.Fatal,
Message = Message,
LogFile(Text); ExecutionTime = GetExecutionTime()
});
} }
} }
@ -208,5 +265,14 @@ namespace Ryujinx.Core
} }
return result.ToString(); return result.ToString();
} }
private struct LogEntry
{
public string CallingMember;
public string ExecutionTime;
public string Message;
public int CallingLineNumber;
public LogLevel LogLevel;
}
} }
} }

View file

@ -221,7 +221,7 @@ namespace Ryujinx.Core.OsHle.Svc
string Str = AMemoryHelper.ReadAsciiString(Memory, Position, Size); string Str = AMemoryHelper.ReadAsciiString(Memory, Position, Size);
Logging.Info($"SvcOutputDebugString: {Str}"); Logging.Info(Str);
ThreadState.X0 = 0; ThreadState.X0 = 0;
} }