Last active
February 8, 2018 02:43
-
-
Save GeorgiyRyaposov/57d432a4776b37e0582be93345cba3a6 to your computer and use it in GitHub Desktop.
Send debug logs to google forms from unity
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; | |
namespace Assets.Utils | |
{ | |
public class LogsMonitor : MonoBehaviour | |
{ | |
public string BaseUrl = "https://docs.google.com/forms/d/11111111111111__QIK5YZFhI8R_3e91Zgcy9ULlcPYc/formResponse"; | |
public string VersionField = "entry.1111111111"; | |
public string PlayerNameField = "entry.111111111"; | |
public string LogsField = "entry.1111111111"; | |
private string _version; | |
#if !UNITY_EDITOR | |
void OnEnable() | |
{ | |
_version = GlobalConfig.Instance.Version; | |
Application.logMessageReceived += HandleLog; | |
} | |
void OnDisable() | |
{ | |
Application.logMessageReceived -= HandleLog; | |
} | |
#endif | |
void HandleLog(string logString, string stackTrace, LogType type) | |
{ | |
if (type != LogType.Error && type != LogType.Exception) | |
return; | |
StartCoroutine(Post(string.Format("{0}\n{1}", logString, stackTrace))); | |
} | |
IEnumerator Post(string logs) | |
{ | |
WWWForm form = new WWWForm(); | |
form.AddField(VersionField, _version); | |
form.AddField(PlayerNameField, string.Format("{0} - {1}", GameContext.Current.Username, SystemInfo.deviceName)); | |
form.AddField(LogsField, logs); | |
byte[] rawData = form.data; | |
WWW www = new WWW(BaseUrl, rawData); | |
yield return www; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment