- Home /
Debug.Log Override?
Is it possible to change the Debug.Log void and if so is anything like this close:
using UnityEngine;
using System.Collections;
public class Debug : MonoBehaviour {
public override void Log (string debugMsg) {
base.Log ();
var example = "Hey";
}
}
Answer by DanSuperGP · Jan 15, 2015 at 08:11 PM
Debug.Log is a static method, so you can't override it. You also can't create Static Extension methods, Extension methods only work on instances.
You could create your own Logger class with it's own Static logging functionality which has the improvements you want. There are even some of these on the asset store.
I'm not sure what you're trying to do with that example.
I really simply want to catch all errors/debugs and log them to a file. I got the log to file working, I only need to get the logging, and Application.RegisterLogCallback() only catches errors/debugs on the script it is attached to.
It shouldn't. You are registering it with the Application itself, it should trap any logs called.
Apparently there's an issue with only trapping logs on the same thread however. It may be that you are only seeing logs from the script it's being attached to because of threading issues.
http://docs.unity3d.com/ScriptReference/Application.RegisterLogCallbackThreaded.html
I am not using multiple thread (Excepts for A* which is using multithreading if I am not mistaking) But all the other scripts is on the same thread.
I am registering it like this:
void Start(){
Application.RegisterLogCallback(Logger);
}
And the logger function looks like this:
public void Logger(string text, string stackTrace, LogType type) {
Game.LogToFile(text);
if (type == LogType.Error || type == LogType.Assert) {
$$anonymous$$essageForLog = text;
}
}
And Game.LogToFile never gets called so it isn't getting longer than this. (Apart from when I run a debug.log on the current script.
Answer by wubak · Oct 31, 2015 at 12:41 PM
FYI RegisterLogCallback is now deprecated.
Now, you want to use the event:
Application.logMessageReceived += HandlerMethodName;
The handler signature must be: HandlerMethodName(string logString, string stackTrace, LogType type)
Answer by ExtremePowers · Jan 15, 2015 at 09:09 PM
I found the bug, you have to call Application.RegisterLogCallback in the same frame as the Debug.Log is called :)
Your answer
Follow this Question
Related Questions
Is there a way to set Unity to write message log when the calculation has Infinity or NaN? 3 Answers
Have my debug log saved to a .log file in build. 2 Answers
Reading the profiler log 0 Answers
Debug.Log is causing an Assert 2 Answers
Debug.log,print not working when run from mobile android 0 Answers