Web server mod for Techblox to run commands
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.0KB

  1. using System;
  2. using System.Threading.Tasks;
  3. using UnityEngine;
  4. using Object = UnityEngine.Object;
  5. namespace TBConsole
  6. {
  7. public class UnityLogHandler : ILogHandler
  8. {
  9. private readonly ILogHandler _original;
  10. private string _collectedLog = null;
  11. public UnityLogHandler(ILogHandler original) => _original = original;
  12. public void LogFormat(LogType logType, Object context, string format, params object[] args)
  13. {
  14. if (_collectedLog != null)
  15. _collectedLog += $"{logType} - {string.Format(format, args)} - {context}\n";
  16. _original.LogFormat(logType, context, format, args);
  17. }
  18. public void LogException(Exception exception, Object context)
  19. {
  20. _original.LogException(exception, context);
  21. }
  22. public void StartCollectingLogMessages() => _collectedLog = "";
  23. public string FinishCollectingLogMessages()
  24. {
  25. string ret = _collectedLog;
  26. _collectedLog = null;
  27. return ret;
  28. }
  29. }
  30. }