diff --git a/LogOutputHandler.cs b/LogOutputHandler.cs index c173262..0156ca0 100644 --- a/LogOutputHandler.cs +++ b/LogOutputHandler.cs @@ -1,38 +1,41 @@ -/// -/// Basic controller that takes logs from Unity's debug.log function and sends output to Loggly -/// -/// USAGE: Simply put this script in your scripts folder and it will operate. -/// Created by Mike Turner of Charmed Matter Games. - using UnityEngine; using System.Collections; public class LogOutputHandler : MonoBehaviour { - //Register the HandleLog function on scene start to fire on debug.log events - void Awake(){ - Application.RegisterLogCallback(HandleLog); - } - - //Create a string to store log level in - string level = ""; - - //Capture debug.log output, send logs to Loggly - public void HandleLog(string logString, string stackTrace, LogType type) { - - //Initialize WWWForm and store log level as a string - level = type.ToString (); - var loggingForm = new WWWForm(); - - //Add log message to WWWForm - loggingForm.AddField("LEVEL", level); - loggingForm.AddField("Message", logString); - loggingForm.AddField("Stack_Trace", stackTrace); - - //Add any User, Game, or Device MetaData that would be useful to finding issues later - loggingForm.AddField("Device_Model", SystemInfo.deviceModel); - - //Send WWW Form to Loggly, replace TOKEN with your unique ID from Loggly - var sendLog = new WWW("http://logs-01.loggly.com/inputs/TOKEN/tag/http/", loggingForm); + //Register the HandleLog function on scene start to fire on debug.log events + public void OnEnable(){ + Application.logMessageReceived += HandleLog; + } + + //Remove callback when object goes out of scope + public void OnDisable(){ + Application.logMessageReceived -= HandleLog; + } + + //Create a string to store log level in + string level = ""; + + //Capture debug.log output, send logs to Loggly + public void HandleLog(string logString, string stackTrace, LogType type) { + + //Initialize WWWForm and store log level as a string + level = type.ToString (); + var loggingForm = new WWWForm(); + + //Add log message to WWWForm + loggingForm.AddField("LEVEL", level); + loggingForm.AddField("Message", logString); + loggingForm.AddField("Stack_Trace", stackTrace); + + //Add any User, Game, or Device MetaData that would be useful to finding issues later + loggingForm.AddField("Device_Model", SystemInfo.deviceModel); + StartCoroutine(SendData(loggingForm)); } + + public IEnumerator SendData(WWWForm form){ + //Send WWW Form to Loggly, replace TOKEN with your unique ID from Loggly + WWW sendLog = new WWW("http://logs-01.loggly.com/inputs/TOKEN/tag/Unity3D", form); + yield return sendLog; + } } diff --git a/LogOutputHandler.js b/LogOutputHandler.js new file mode 100644 index 0000000..f55c673 --- /dev/null +++ b/LogOutputHandler.js @@ -0,0 +1,31 @@ +#pragma strict + +//Register the HandleLog function on scene start to fire on debug.log events +function OnEnable () { + Application.logMessageReceived += HandleLog; +} + +//Remove callback when object goes out of scope +function OnDisable () { + Application.logMessageReceived -= HandleLog; +} + +function HandleLog (logString : String, stackTrace : String, type : LogType) { + //Initialize WWWForm and store log level as a string + var level = type.ToString (); + var loggingForm = new WWWForm(); + + //Add log message to WWWForm + loggingForm.AddField("LEVEL", level); + loggingForm.AddField("Message", logString); + loggingForm.AddField("Stack_Trace", stackTrace); + + //Add any User, Game, or Device MetaData that would be useful to finding issues later + loggingForm.AddField("Device_Model", SystemInfo.deviceModel); + SendStuff(loggingForm); +} +function SendStuff(form : WWWForm){ + //Send WWW Form to Loggly, replace TOKEN with your unique ID from Loggly + var sendLog = new WWW("http://logs-01.loggly.com/inputs/TOKEN/tag/Unity3D", form); + yield sendLog; +} diff --git a/README.md b/README.md index d157d85..326546d 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,5 @@ Basic controller that takes logs from Unity's debug.log function and sends output to Loggly USAGE: Simply put this script in your scripts folder and it will operate. Created by Mike Turner of Charmed Matter Games. + +Check out Loggly's [Unity3D logging documentation](https://www.loggly.com/docs/unity-3d/) to learn more.