2023-04-03 12:14:19 +02:00
|
|
|
|
using System.Text;
|
2019-02-11 13:00:32 +01:00
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Common.Logging
|
|
|
|
|
{
|
|
|
|
|
internal class DefaultLogFormatter : ILogFormatter
|
|
|
|
|
{
|
2023-04-03 12:14:19 +02:00
|
|
|
|
private static readonly ObjectPool<StringBuilder> StringBuilderPool = SharedPools.Default<StringBuilder>();
|
2019-02-11 13:00:32 +01:00
|
|
|
|
|
|
|
|
|
public string Format(LogEventArgs args)
|
|
|
|
|
{
|
2023-04-03 12:14:19 +02:00
|
|
|
|
StringBuilder sb = StringBuilderPool.Allocate();
|
2019-02-11 13:00:32 +01:00
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
sb.Clear();
|
|
|
|
|
|
2023-04-03 12:14:19 +02:00
|
|
|
|
sb.Append($@"{args.Time:hh\:mm\:ss\.fff}");
|
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);
|
|
|
|
|
|
2023-04-03 12:14:19 +02:00
|
|
|
|
if (args.Data is not null)
|
2019-02-11 13:00:32 +01:00
|
|
|
|
{
|
2023-04-03 12:14:19 +02:00
|
|
|
|
sb.Append(' ');
|
|
|
|
|
DynamicObjectFormatter.Format(sb, args.Data);
|
2019-02-11 13:00:32 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
2023-04-03 12:14:19 +02:00
|
|
|
|
StringBuilderPool.Release(sb);
|
2019-02-11 13:00:32 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|