Created
January 24, 2019 21:41
-
-
Save arkms/3ff1d79b51e5cf2119d007e4a0fddacb to your computer and use it in GitHub Desktop.
Unity: Enviar Logs de consola por email para ejecutables de PC, Mac, Linux, Android, iOS, AppleTV y WebGL.
This file contains 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 System.Text; | |
using UnityEngine; | |
public class DebugLogEmail : MonoBehaviour | |
{ | |
//Llamar desde un boton o presionar una tecla para enviar los logs por email | |
public void MandarEmail() | |
{ | |
StartCoroutine(SendData()); | |
} | |
//Pedimos a Unity que nos envie los Logs | |
public void OnEnable() | |
{ | |
if (InScene) return; //Ya tenemos uno en escena, no hacemos nada | |
InScene = true; | |
DontDestroyOnLoad(gameObject); | |
Application.logMessageReceived += HandleLog; | |
} | |
//Nos quitamos cuando de desactiva este Objecto | |
public void OnDisable() | |
{ | |
Application.logMessageReceived -= HandleLog; | |
InScene = false; | |
} | |
//Donde almacenamos los logs | |
StringBuilder log = new StringBuilder(); | |
//Funcion que recivira los Debug.Log() | |
public void HandleLog(string _logString, string _stackTrace, LogType _tipo) | |
{ | |
string msg = ""; | |
switch (_tipo) | |
{ | |
case LogType.Error: | |
msg = "[Error] "; | |
break; | |
case LogType.Assert: | |
msg = "[Assert] "; | |
break; | |
case LogType.Warning: | |
msg = "[Warning] "; | |
break; | |
case LogType.Log: | |
msg = "[Log] "; | |
break; | |
case LogType.Exception: | |
msg = "[Exception] "; | |
break; | |
} | |
msg += _logString + "\n" + _stackTrace; | |
log.Append(log); | |
} | |
IEnumerator SendData() | |
{ | |
WWWForm form= new WWWForm(); | |
form.AddField("msg", log.ToString()); | |
//Mandamos mensaje a nuestro servidor | |
WWW sendLog = new WWW("URLServer/DebugLogEmail.php", form); | |
yield return sendLog; | |
log.Length = 0; | |
} | |
private static bool InScene = false; //Ayudara evitar que haya más de uno | |
} |
This file contains 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
<?php | |
/*Uso: | |
1 Configurar lo que se encuentra en mayusculas de $from y $to | |
2 Subirlo a un servidor que soporte php | |
3 Actualizar el script de Unity en la linea 66 con la URL donde hospedes este archivo*/ | |
$from = "reporter@TUDOMINIO.COM "; //Recomendado que sea @nombreDominio para evitar sea enviado a spam | |
$to = "TUEMAIL"; //Donde deseas recibirlo | |
$subject = "Unity Log Report"; | |
$message = $_POST["msg"]; | |
$headers = "From:".$from; | |
mail($to,$subject,$message, $headers); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment