Process logged data objects in the logger target
Pass the data object all the way to the output logger targets, to allow them to "serialize" this in whatever appropriate format they're logging in.
This commit is contained in:
parent
b2343a86bf
commit
aea08270ac
3 changed files with 51 additions and 43 deletions
|
@ -9,13 +9,23 @@ namespace Ryujinx.Common.Logging
|
|||
public int ThreadId { get; private set; }
|
||||
|
||||
public string Message { get; private set; }
|
||||
public object Data { get; private set; }
|
||||
|
||||
public LogEventArgs(LogLevel level, TimeSpan time, int threadId, string message)
|
||||
{
|
||||
this.Level = level;
|
||||
this.Time = time;
|
||||
this.Level = level;
|
||||
this.Time = time;
|
||||
this.ThreadId = threadId;
|
||||
this.Message = message;
|
||||
}
|
||||
|
||||
public LogEventArgs(LogLevel level, TimeSpan time, int threadId, string message, object data)
|
||||
{
|
||||
this.Level = level;
|
||||
this.Time = time;
|
||||
this.ThreadId = threadId;
|
||||
this.Message = message;
|
||||
this.Data = data;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -71,46 +71,12 @@ namespace Ryujinx.Common.Logging
|
|||
|
||||
public static void PrintStub<T>(LogClass logClass, T obj, [CallerMemberName] string caller = "")
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
PropertyInfo[] props = typeof(T).GetProperties();
|
||||
|
||||
sb.Append("Stubbed. ");
|
||||
|
||||
foreach (var prop in props)
|
||||
{
|
||||
sb.Append($"{prop.Name}: {prop.GetValue(obj)}");
|
||||
sb.Append(" - ");
|
||||
}
|
||||
|
||||
if (props.Length > 0)
|
||||
{
|
||||
sb.Remove(sb.Length - 3, 3);
|
||||
}
|
||||
|
||||
Print(LogLevel.Stub, logClass, GetFormattedMessage(logClass, sb.ToString(), caller));
|
||||
Print(LogLevel.Stub, logClass, GetFormattedMessage(logClass, "Stubbed.", caller), obj);
|
||||
}
|
||||
|
||||
public static void PrintStub<T>(LogClass logClass, string message, T obj, [CallerMemberName] string caller = "")
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
PropertyInfo[] props = typeof(T).GetProperties();
|
||||
|
||||
sb.Append("Stubbed. ");
|
||||
sb.Append(message);
|
||||
sb.Append(' ');
|
||||
|
||||
foreach (var prop in props)
|
||||
{
|
||||
sb.Append($"{prop.Name}: {prop.GetValue(obj)}");
|
||||
sb.Append(" - ");
|
||||
}
|
||||
|
||||
if (props.Length > 0)
|
||||
{
|
||||
sb.Remove(sb.Length - 3, 3);
|
||||
}
|
||||
|
||||
Print(LogLevel.Stub, logClass, GetFormattedMessage(logClass, sb.ToString(), caller));
|
||||
Print(LogLevel.Stub, logClass, GetFormattedMessage(logClass, "Stubbed. " + message, caller), obj);
|
||||
}
|
||||
|
||||
private static void Print(LogLevel logLevel, LogClass logClass, string message)
|
||||
|
@ -121,6 +87,14 @@ namespace Ryujinx.Common.Logging
|
|||
}
|
||||
}
|
||||
|
||||
private static void Print(LogLevel logLevel, LogClass logClass, string message, object data)
|
||||
{
|
||||
if (m_EnabledLevels[(int)logLevel] && m_EnabledClasses[(int)logClass])
|
||||
{
|
||||
Updated?.Invoke(null, new LogEventArgs(logLevel, m_Time.Elapsed, Thread.CurrentThread.ManagedThreadId, message, data));
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetFormattedMessage(LogClass Class, string Message, string Caller)
|
||||
{
|
||||
return $"{Class} {Caller}: {Message}";
|
||||
|
|
|
@ -2,6 +2,8 @@ using Ryujinx.Common.Logging;
|
|||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
|
||||
namespace Ryujinx
|
||||
|
@ -51,22 +53,44 @@ namespace Ryujinx
|
|||
|
||||
private static void PrintLog(LogEventArgs e)
|
||||
{
|
||||
string formattedTime = e.Time.ToString(@"hh\:mm\:ss\.fff");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
string currentThread = e.ThreadId.ToString("d4");
|
||||
sb.AppendFormat(@"{0:hh\:mm\:ss\.fff}", e.Time);
|
||||
sb.Append(" | ");
|
||||
sb.AppendFormat("{0:d4}", e.ThreadId);
|
||||
sb.Append(' ');
|
||||
sb.Append(e.Message);
|
||||
|
||||
string message = formattedTime + " | " + currentThread + " " + e.Message;
|
||||
if (e.Data != null)
|
||||
{
|
||||
PropertyInfo[] props = e.Data.GetType().GetProperties();
|
||||
|
||||
sb.Append(' ');
|
||||
|
||||
foreach (var prop in props)
|
||||
{
|
||||
sb.Append($"{prop.Name}: {prop.GetValue(e.Data)}");
|
||||
sb.Append(" - ");
|
||||
}
|
||||
|
||||
// We remove the final '-' from the string
|
||||
if (props.Length > 0)
|
||||
{
|
||||
sb.Remove(sb.Length - 3, 3);
|
||||
}
|
||||
}
|
||||
|
||||
if (_logColors.TryGetValue(e.Level, out ConsoleColor color))
|
||||
{
|
||||
Console.ForegroundColor = color;
|
||||
|
||||
Console.WriteLine(message);
|
||||
Console.WriteLine(sb.ToString());
|
||||
|
||||
Console.ResetColor();
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine(message);
|
||||
Console.WriteLine(sb.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue