Sample11_Logger.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using System.Collections;
  3. using UniRx.Diagnostics;
  4. using UnityEngine;
  5. namespace UniRx.Examples
  6. {
  7. public class Sample11_Logger
  8. {
  9. // UniRx.Diagnostics.Logger
  10. // logger is threadsafe, define per class with name.
  11. static readonly UniRx.Diagnostics.Logger logger = new UniRx.Diagnostics.Logger("Sample11");
  12. // call once at applicationinit
  13. public void ApplicationInitialize()
  14. {
  15. // Log as Stream, UniRx.Diagnostics.ObservableLogger.Listener is IObservable<LogEntry>
  16. // You can subscribe and output to any place.
  17. ObservableLogger.Listener.LogToUnityDebug();
  18. // for example, filter only Exception and upload to web.
  19. // (make custom sink(IObserver<EventEntry>) is better to use)
  20. ObservableLogger.Listener
  21. .Where(x => x.LogType == LogType.Exception)
  22. .Subscribe(x =>
  23. {
  24. // ObservableWWW.Post("", null).Subscribe();
  25. });
  26. }
  27. public void Run()
  28. {
  29. // Debug is write only DebugBuild.
  30. logger.Debug("Debug Message");
  31. // or other logging methods
  32. logger.Log("Message");
  33. logger.Exception(new Exception("test exception"));
  34. }
  35. }
  36. }