TBConsole/TBConsole/UnityLogHandler.cs
NorbiPeti 7a6cc79e61
Not waiting for the response, command list endpoint
Returning the response right after the command is executed, most of the time that's enough, long polling should be used in addition
2021-05-25 00:49:50 +02:00

35 lines
No EOL
1 KiB
C#

using System;
using System.Threading.Tasks;
using UnityEngine;
using Object = UnityEngine.Object;
namespace TBConsole
{
public class UnityLogHandler : ILogHandler
{
private readonly ILogHandler _original;
private string _collectedLog = null;
public UnityLogHandler(ILogHandler original) => _original = original;
public void LogFormat(LogType logType, Object context, string format, params object[] args)
{
if (_collectedLog != null)
_collectedLog += $"{logType} - {string.Format(format, args)} - {context}\n";
_original.LogFormat(logType, context, format, args);
}
public void LogException(Exception exception, Object context)
{
_original.LogException(exception, context);
}
public void StartCollectingLogMessages() => _collectedLog = "";
public string FinishCollectingLogMessages()
{
string ret = _collectedLog;
_collectedLog = null;
return ret;
}
}
}