Last active
August 15, 2020 07:09
-
-
Save neogeek/46e7896edaf8a59089b19fb07577555f to your computer and use it in GitHub Desktop.
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 UnityEngine; | |
using UnityEngine.Networking; | |
namespace LumberLogs | |
{ | |
public class Logger : MonoBehaviour | |
{ | |
#pragma warning disable CS0649 | |
[SerializeField] | |
private string url; | |
#pragma warning restore CS0649 | |
private int failedConnections; | |
private const int maxFailedConnections = 10; | |
#if UNITY_EDITOR || DEVELOPMENT_BUILD | |
private void OnEnable() | |
{ | |
Application.logMessageReceived += HandleLog; | |
} | |
private void OnDisable() | |
{ | |
Application.logMessageReceived -= HandleLog; | |
} | |
#endif | |
private void HandleLog(string logString, string stackTrace, LogType type) | |
{ | |
if (url == null || failedConnections >= maxFailedConnections) | |
{ | |
return; | |
} | |
var loggingForm = new WWWForm(); | |
loggingForm.AddField("Type", type.ToString()); | |
loggingForm.AddField("Message", logString); | |
loggingForm.AddField("Stack_Trace", stackTrace); | |
loggingForm.AddField("Device_Model", SystemInfo.deviceModel); | |
StartCoroutine(SendDataToLumberLog(loggingForm)); | |
} | |
private IEnumerator SendDataToLumberLog(WWWForm form) | |
{ | |
using (var www = UnityWebRequest.Post(url, form)) | |
{ | |
yield return www.SendWebRequest(); | |
if (!www.isNetworkError && !www.isHttpError) | |
{ | |
yield break; | |
} | |
Debug.LogError(www.error); | |
failedConnections += 1; | |
} | |
} | |
} | |
} |
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
fileFormatVersion: 2 | |
guid: 54098c83cc90b45bb9d72178609b7d64 | |
MonoImporter: | |
externalObjects: {} | |
serializedVersion: 2 | |
defaultReferences: [] | |
executionOrder: 0 | |
icon: {instanceID: 0} | |
userData: | |
assetBundleName: | |
assetBundleVariant: |
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
{ | |
"name": "LumberLogs" | |
} |
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
fileFormatVersion: 2 | |
guid: f83e7ec76431346329b76b1aa2545535 | |
AssemblyDefinitionImporter: | |
externalObjects: {} | |
userData: | |
assetBundleName: | |
assetBundleVariant: |
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
{ | |
"name": "com.scottdoxey.lumberlogs", | |
"displayName": "Lumber Logs", | |
"version": "1.0.0", | |
"unity": "2019.3", | |
"description": "A self-hosted log aggregation tool." | |
} |
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
fileFormatVersion: 2 | |
guid: b6675c8348c1c404783a4f1abae64ecf | |
TextScriptImporter: | |
externalObjects: {} | |
userData: | |
assetBundleName: | |
assetBundleVariant: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment