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