From 4dc7b7ce5ae0332ea9e9ff8a8df534d576e6b56d Mon Sep 17 00:00:00 2001 From: Tiago Loureiro Date: Fri, 4 Mar 2016 18:20:53 +0000 Subject: [PATCH 1/3] Update to Unity 5.x Since the current examples do not work with Unity 5.x I made the following changes to the already existing scripts, and also included a new UnityScript file to the lot. * Change #1 Application.RegisterLogCallback(HandleLog); this has been deprecated in version 5, so I basically changed it to: public void OnEnable(){ Application.logMessageReceived += HandleLog; } public void OnDisable(){ Application.logMessageReceived -= HandleLog; } Where we send logs when the object is active and stop when it is inactive. * Change #2 /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/", loggingForm); Did two things here. The communication per se (the WWW object) is handled on a separate function, mainly because of the coroutine handling in c# and now I force the message to be sent with yield, ergo removing any concurrency issues. My code: 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; } Have fun :) --- LogOutputHandler.cs | 67 +++++++++++++++++++++++---------------------- LogOutputHandler.js | 31 +++++++++++++++++++++ 2 files changed, 66 insertions(+), 32 deletions(-) create mode 100644 LogOutputHandler.js diff --git a/LogOutputHandler.cs b/LogOutputHandler.cs index c173262..39c5189 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; +} From dc71126418c942350243d6f34e9b9ece1fe37962 Mon Sep 17 00:00:00 2001 From: Tiago Loureiro Date: Thu, 10 Mar 2016 00:03:52 +0000 Subject: [PATCH 2/3] Corrected tabs Just found that Atom has a default set to look at the files and not at the editor's settings when trying to select whether hard or soft tabs. Fixed indentation and already updated Atom's settings so it won't happen again. --- LogOutputHandler.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/LogOutputHandler.cs b/LogOutputHandler.cs index 39c5189..19cdd16 100644 --- a/LogOutputHandler.cs +++ b/LogOutputHandler.cs @@ -5,12 +5,12 @@ public class LogOutputHandler : MonoBehaviour { //Register the HandleLog function on scene start to fire on debug.log events public void OnEnable(){ - Application.logMessageReceived += HandleLog; + Application.logMessageReceived += HandleLog; } //Remove callback when object goes out of scope - public void OnDisable(){ - Application.logMessageReceived -= HandleLog; + public void OnDisable(){ + Application.logMessageReceived -= HandleLog; } //Create a string to store log level in @@ -22,20 +22,20 @@ 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)); - } + StartCoroutine(SendData(loggingForm)); + } - public IEnumerator SendData(WWWForm form){ + 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; + yield return sendLog; } } From 82dfdc4e16dcb2eafa9ae736487b808ad7b72fe5 Mon Sep 17 00:00:00 2001 From: Tiago Loureiro Date: Thu, 10 Mar 2016 00:27:52 +0000 Subject: [PATCH 3/3] Fixed all the tabs that got screwed over through the online editor. --- LogOutputHandler.cs | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/LogOutputHandler.cs b/LogOutputHandler.cs index 19cdd16..0156ca0 100644 --- a/LogOutputHandler.cs +++ b/LogOutputHandler.cs @@ -9,7 +9,7 @@ public void OnEnable(){ } //Remove callback when object goes out of scope - public void OnDisable(){ + public void OnDisable(){ Application.logMessageReceived -= HandleLog; } @@ -19,23 +19,23 @@ public void OnDisable(){ //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)); + //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; + 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; } }