0
0
Fork 0
mirror of https://github.com/GreemDev/Ryujinx.git synced 2025-01-25 17:31:59 +00:00
Ryujinx/src/Ryujinx.Common/Logging/Formatters/DefaultLogFormatter.cs
TSRBerry 2989c163a8
editorconfig: Set default encoding to UTF-8 (#5793)
* editorconfig: Add default charset

* Change file encoding from UTF-8-BOM to UTF-8
2023-12-04 14:17:13 +01:00

51 lines
1.3 KiB
C#

using System.Diagnostics;
using System.Text;
namespace Ryujinx.Common.Logging.Formatters
{
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.Append($@"{args.Time:hh\:mm\:ss\.fff}");
sb.Append($" |{args.Level.ToString()[0]}| ");
if (args.ThreadName != null)
{
sb.Append(args.ThreadName);
sb.Append(' ');
}
sb.Append(args.Message);
if (args.Data is not null)
{
if (args.Data is StackTrace trace)
{
sb.Append('\n');
sb.Append(trace);
return sb.ToString();
}
sb.Append(' ');
DynamicObjectFormatter.Format(sb, args.Data);
}
return sb.ToString();
}
finally
{
_stringBuilderPool.Release(sb);
}
}
}
}