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