Created
May 11, 2017 09:33
-
-
Save ApprenticeGC/910459422b77b649cd711706a5e16546 to your computer and use it in GitHub Desktop.
Combine UniRx with Loggly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Collections; | |
| using System.Collections.Generic; | |
| using UnityEngine; | |
| using UniRx; | |
| public class LoggerFromUniRx : MonoBehaviour | |
| { | |
| private class LogCallback | |
| { | |
| public string Condition; | |
| public string StackTrace; | |
| public UnityEngine.LogType LogType; | |
| } | |
| static class LogHelper | |
| { | |
| public static IObservable<LogCallback> LogCallbackAsObservable() | |
| { | |
| return Observable.FromEvent<Application.LogCallback, LogCallback>( | |
| h => (condition, stackTrace, type) => h(new LogCallback { Condition = condition, StackTrace = stackTrace, LogType = type }), | |
| h => Application.logMessageReceived += h, | |
| h => Application.logMessageReceived -= h); | |
| } | |
| } | |
| void Awake() | |
| { | |
| // method is separatable and composable | |
| // LogHelper.LogCallbackAsObservable() | |
| // .Where(x => x.LogType == LogType.Warning) | |
| // .Subscribe(x => Debug.Log(x)); | |
| LogHelper.LogCallbackAsObservable() | |
| .Where(x => x.LogType == LogType.Log) | |
| .Subscribe(x => | |
| { | |
| var loggingForm = new WWWForm(); | |
| loggingForm.AddField("Message", x.Condition); | |
| loggingForm.AddField("Stack_Trace", x.StackTrace); | |
| ObservableWWW.Post("http://logs-01.loggly.com/inputs/1b5d1fde-cc58-4f40-bb24-a201b2016a2f/tag/apus", loggingForm) | |
| .Timeout(System.TimeSpan.FromSeconds(30)) | |
| .Subscribe(result => | |
| { | |
| }); | |
| }); | |
| // LogHelper.LogCallbackAsObservable() | |
| // .Where(x => x.LogType == LogType.Error) | |
| // .Subscribe(x => Debug.Log(x)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment