x


Capturing log messages

I tried to capture the log output using Application.RegisterLogCallback but it did not work:

int logcalled ;

// Use this for initialization
void OnEnable() {
    UnityEngine.Application.RegisterLogCallback(new Application.LogCallback(MyCallback));
}

private void MyCallback(string condition, string stacktrace, UnityEngine.LogType type)
{
	logcalled++;
}

void OnGUI(){ 
	GUI.Label(new Rect(10,10,100,100), logcalled.ToString());

	if(GUI.Button(new Rect(100,100,100,100),"press"))
	{
		Debug.LogError("iada iada");
		Debug.Log("iada iada 2");
		object a = null;
		a.ToString();
	}
}

The above code dont work, the variable logcalled not incremented.

  • Tried Debug.Log, Debug.LogError and a even a null exception, neither was captured, but they where all logged to the editor console.
  • Tried to register the callback on "Start" with the same results.
  • Tried a Debug.Log on the "Update" method, generating dozens of log msg/second. In this case 'logcalled' was called 2 times at the very begining and that was it.
  • Tried using javascript instead of C#, didnt work either.

Am I missing something?

(question was edited to clarify it)

more ▼

asked Feb 14 '10 at 02:00 PM

Andre Galastri gravatar image

Andre Galastri
109 2 2 8

(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

There seems to be a bug with this.

The only way I could get RegisterLogCallback to work with our in-game logging system was by calling RegisterLogCallback every frame. If I just called it at startup, it would only call the logs that were in that initial frame.

more ▼

answered Mar 02 '10 at 05:34 PM

Tetrad gravatar image

Tetrad
7.3k 27 37 89

It seems from my testing that you can't register it until at least two frames after starting. You don't need to call it every frame, since once it "takes," it's set.

Mar 02 '10 at 07:05 PM burnumd

Indeed! After some tests, registering on the third frame solve it. But wtf, and if in the next update this changes to the fourht frame? Just kidding of course, its just to strange to be confortable, but whatever, works for now.

Mar 04 '10 at 11:45 AM Andre Galastri

The issue apparently was fixed at some point, in 3.4.2 a callback registered in the very first frame works fine.

Nov 28 '11 at 06:57 PM volk
(comments are locked)
10|3000 characters needed characters left

RegisterLogCallback should not redirect the log output - it should install an additional handler, so the log output goes to the editor log, and your function should be called. Are you seeing logcalled being incremented as log messages are printed? If so, then everything works as expected.

more ▼

answered Feb 15 '10 at 09:09 AM

jonas echterhoff gravatar image

jonas echterhoff ♦♦
9.8k 7 23 104

Thats the problem, 'logcalled' is not being incremented!

The example on the unity site uses a Javascript, could this be relevant?

Feb 17 '10 at 06:53 PM Andre Galastri
(comments are locked)
10|3000 characters needed characters left

The JavaScript example in Unity's documentation also does not work (unless you use the delayed register workaround) . Has anyone logged a bug report?

more ▼

answered Jun 18 '10 at 11:57 PM

Fernando Zapata 1 gravatar image

Fernando Zapata 1
11 1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x70

asked: Feb 14 '10 at 02:00 PM

Seen: 2069 times

Last Updated: Nov 28 '11 at 06:57 PM