2023-04-03 06:14:19 -04:00
|
|
|
|
using System.Text;
|
2019-02-11 07:00:32 -05:00
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Common.Logging
|
|
|
|
|
{
|
|
|
|
|
internal class DefaultLogFormatter : ILogFormatter
|
|
|
|
|
{
|
2023-04-03 06:14:19 -04:00
|
|
|
|
private static readonly ObjectPool<StringBuilder> StringBuilderPool = SharedPools.Default<StringBuilder>();
|
2019-02-11 07:00:32 -05:00
|
|
|
|
|
|
|
|
|
public string Format(LogEventArgs args)
|
|
|
|
|
{
|
2023-04-03 06:14:19 -04:00
|
|
|
|
StringBuilder sb = StringBuilderPool.Allocate();
|
2019-02-11 07:00:32 -05:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
sb.Clear();
|
|
|
|
|
|
2023-04-03 06:14:19 -04:00
|
|
|
|
sb.Append($@"{args.Time:hh\:mm\:ss\.fff}");
|
2020-08-03 19:32:53 -04:00
|
|
|
|
sb.Append($" |{args.Level.ToString()[0]}| ");
|
2020-01-12 19:21:54 -05:00
|
|
|
|
|
|
|
|
|
if (args.ThreadName != null)
|
|
|
|
|
{
|
|
|
|
|
sb.Append(args.ThreadName);
|
|
|
|
|
sb.Append(' ');
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-11 07:00:32 -05:00
|
|
|
|
sb.Append(args.Message);
|
|
|
|
|
|
2023-04-03 06:14:19 -04:00
|
|
|
|
if (args.Data is not null)
|
2019-02-11 07:00:32 -05:00
|
|
|
|
{
|
2023-04-03 06:14:19 -04:00
|
|
|
|
sb.Append(' ');
|
|
|
|
|
DynamicObjectFormatter.Format(sb, args.Data);
|
2019-02-11 07:00:32 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
2023-04-03 06:14:19 -04:00
|
|
|
|
StringBuilderPool.Release(sb);
|
2019-02-11 07:00:32 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|