ObservableLogger.cs 779 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using UnityEngine;
  5. namespace UniRx.Diagnostics
  6. {
  7. public class ObservableLogger : IObservable<LogEntry>
  8. {
  9. static readonly Subject<LogEntry> logPublisher = new Subject<LogEntry>();
  10. public static readonly ObservableLogger Listener = new ObservableLogger();
  11. private ObservableLogger()
  12. {
  13. }
  14. public static Action<LogEntry> RegisterLogger(Logger logger)
  15. {
  16. if (logger.Name == null) throw new ArgumentNullException("logger.Name is null");
  17. return logPublisher.OnNext;
  18. }
  19. public IDisposable Subscribe(IObserver<LogEntry> observer)
  20. {
  21. return logPublisher.Subscribe(observer);
  22. }
  23. }
  24. }