- Home /
Debug log to website.
im trying to make it so that when i make apps or something that is build. it sends it debug log to a website. i have my own webspace so i can use php and stuff.
just a blank page that only shows my debug.logs.
i know its possible because i have seen it before, dont know where.
if you guys could help me that would be amazing.
so i call debug.log function or a function that puts it in a string or so.
sends to my website blank page.
and just add new line when new debug.log is send
thanks in advance :D
-v3
Write a customer logger that follows this (HTTP request with POST) to your domain, then take the POST data and copy it to a DB of some sort.
Answer by ByteSheep · Jan 10, 2015 at 10:13 AM
PHP Stuff
Check out the php function file_put_contents to write data to a file.
Example Usage:
<?php
$data = $_POST["debugdata"];
if(isset($data))
{
$file = 'debuglog.txt';
// Write the contents to the file
file_put_contents($file, $data);
}
?>
Unity Stuff
You'll want to look into sending post requests to a url using the www class and create a function with which you can easily add new debug statements. Check here for a way to extend Debug.Log.
Example (Add this to a gameobject in your scene):
using UnityEngine;
using System.Text;
using System.Collections;
public class DebugData : MonoBehaviour
{
public static DebugData Instance;
private StringBuilder sb = new StringBuilder();
void Awake ()
{
Instance = this;
}
public void AddDebug (string log)
{
sb.Append(log);
sb.Append("\n");
}
public void PostDebugData ()
{
StartCoroutine(Post(sb.ToString()));
}
public IEnumerator Post (string data)
{
string url = "http://yoururl.com/yourdebugfile.php";
// Create a Web Form
var form = new WWWForm();
form.AddField("debugdata", data);
WWW w = new WWW(url, form);
yield return w;
if (!string.IsNullOrEmpty(w.error))
print(w.error);
else
print("Finished sending debug data.");
}
}
Then you can add debug logs using DebugData.Instance.AddDebug("Hello World!"); and post the data using DebugData.Instance.PostDebugData();
Answer by hypnoticmeteor · Jan 10, 2015 at 10:19 AM
Create a table on your website called "Log" with 2 columns "ID" Primary Key and "LogString" as varchar.
Your application will use WWW class and WWWForms.
string Debug_URL = "http://www.url_to_use_with_http";
IEnumerator logData(string logStringToSendToWebServer)
{
WWWForm form = new WWWForm();
form.AddField("logString",logStringToSendToWebServer);
WWW get = new WWW(Debug_URL,form);
yield return get;
if (get.text == "done")
{
//finish code
}
else
{
//fail recovery code
}
}
You php code should be something like this.
#Connect to the database
#check validation of some sort
#Take data
$logValueToEnterIntoDatabase = $_POST["logString"];
#insert data into database by changing the value to be added as $logValueToEnterIntoDatabase
Your answer
Follow this Question
Related Questions
Download HTML source code from link not working 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
WebHosting with phpMyAdmin PHP 0 Answers
App gets stuck on WebGL 0 Answers