2019-06-27 13:11:51 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Reflection;
|
2019-02-11 13:00:32 +01:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Common.Logging
|
|
|
|
|
{
|
|
|
|
|
internal class DefaultLogFormatter : ILogFormatter
|
|
|
|
|
{
|
|
|
|
|
private static readonly ObjectPool<StringBuilder> _stringBuilderPool = SharedPools.Default<StringBuilder>();
|
|
|
|
|
|
|
|
|
|
public string Format(LogEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = _stringBuilderPool.Allocate();
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
sb.Clear();
|
|
|
|
|
|
|
|
|
|
sb.AppendFormat(@"{0:hh\:mm\:ss\.fff}", args.Time);
|
2020-08-04 01:32:53 +02:00
|
|
|
|
sb.Append($" |{args.Level.ToString()[0]}| ");
|
2020-01-13 01:21:54 +01:00
|
|
|
|
|
|
|
|
|
if (args.ThreadName != null)
|
|
|
|
|
{
|
|
|
|
|
sb.Append(args.ThreadName);
|
|
|
|
|
sb.Append(' ');
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-11 13:00:32 +01:00
|
|
|
|
sb.Append(args.Message);
|
|
|
|
|
|
|
|
|
|
if (args.Data != null)
|
|
|
|
|
{
|
|
|
|
|
PropertyInfo[] props = args.Data.GetType().GetProperties();
|
|
|
|
|
|
2020-08-04 01:32:53 +02:00
|
|
|
|
sb.Append(" {");
|
2019-02-11 13:00:32 +01:00
|
|
|
|
|
|
|
|
|
foreach (var prop in props)
|
|
|
|
|
{
|
|
|
|
|
sb.Append(prop.Name);
|
|
|
|
|
sb.Append(": ");
|
2019-06-27 13:11:51 +02:00
|
|
|
|
|
|
|
|
|
if (typeof(Array).IsAssignableFrom(prop.PropertyType))
|
|
|
|
|
{
|
2020-08-04 01:32:53 +02:00
|
|
|
|
Array array = (Array)prop.GetValue(args.Data);
|
|
|
|
|
foreach (var item in array)
|
2019-06-27 13:11:51 +02:00
|
|
|
|
{
|
|
|
|
|
sb.Append(item.ToString());
|
|
|
|
|
sb.Append(", ");
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-04 01:32:53 +02:00
|
|
|
|
if (array.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
sb.Remove(sb.Length - 2, 2);
|
|
|
|
|
}
|
2019-06-27 13:11:51 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sb.Append(prop.GetValue(args.Data));
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-04 01:32:53 +02:00
|
|
|
|
sb.Append(" ; ");
|
2019-02-11 13:00:32 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-04 01:32:53 +02:00
|
|
|
|
// We remove the final ';' from the string
|
2019-02-11 13:00:32 +01:00
|
|
|
|
if (props.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
sb.Remove(sb.Length - 3, 3);
|
|
|
|
|
}
|
2020-08-04 01:32:53 +02:00
|
|
|
|
|
|
|
|
|
sb.Append('}');
|
2019-02-11 13:00:32 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
_stringBuilderPool.Release(sb);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|