2019-06-27 04:11:51 -07:00
|
|
|
|
using System;
|
|
|
|
|
using System.Reflection;
|
2019-02-11 04:00:32 -08: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-03 16:32:53 -07:00
|
|
|
|
sb.Append($" |{args.Level.ToString()[0]}| ");
|
2020-01-12 16:21:54 -08:00
|
|
|
|
|
|
|
|
|
if (args.ThreadName != null)
|
|
|
|
|
{
|
|
|
|
|
sb.Append(args.ThreadName);
|
|
|
|
|
sb.Append(' ');
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-11 04:00:32 -08:00
|
|
|
|
sb.Append(args.Message);
|
|
|
|
|
|
|
|
|
|
if (args.Data != null)
|
|
|
|
|
{
|
|
|
|
|
PropertyInfo[] props = args.Data.GetType().GetProperties();
|
|
|
|
|
|
2020-08-03 16:32:53 -07:00
|
|
|
|
sb.Append(" {");
|
2019-02-11 04:00:32 -08:00
|
|
|
|
|
|
|
|
|
foreach (var prop in props)
|
|
|
|
|
{
|
|
|
|
|
sb.Append(prop.Name);
|
|
|
|
|
sb.Append(": ");
|
2019-06-27 04:11:51 -07:00
|
|
|
|
|
|
|
|
|
if (typeof(Array).IsAssignableFrom(prop.PropertyType))
|
|
|
|
|
{
|
2020-08-03 16:32:53 -07:00
|
|
|
|
Array array = (Array)prop.GetValue(args.Data);
|
|
|
|
|
foreach (var item in array)
|
2019-06-27 04:11:51 -07:00
|
|
|
|
{
|
|
|
|
|
sb.Append(item.ToString());
|
|
|
|
|
sb.Append(", ");
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 16:32:53 -07:00
|
|
|
|
if (array.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
sb.Remove(sb.Length - 2, 2);
|
|
|
|
|
}
|
2019-06-27 04:11:51 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
sb.Append(prop.GetValue(args.Data));
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 16:32:53 -07:00
|
|
|
|
sb.Append(" ; ");
|
2019-02-11 04:00:32 -08:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-03 16:32:53 -07:00
|
|
|
|
// We remove the final ';' from the string
|
2019-02-11 04:00:32 -08:00
|
|
|
|
if (props.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
sb.Remove(sb.Length - 3, 3);
|
|
|
|
|
}
|
2020-08-03 16:32:53 -07:00
|
|
|
|
|
|
|
|
|
sb.Append('}');
|
2019-02-11 04:00:32 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
_stringBuilderPool.Release(sb);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|