Skip to content

Update to Unity 5.x #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 34 additions & 31 deletions LogOutputHandler.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
/// <summary>
/// Basic controller that takes logs from Unity's debug.log function and sends output to Loggly
/// </summary>
/// 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;
}
}
31 changes: 31 additions & 0 deletions LogOutputHandler.js
Original file line number Diff line number Diff line change
@@ -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;
}