Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
10
Question by Andre Galastri · Feb 14, 2010 at 02:00 PM · log

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)

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image freshingrain · Nov 06, 2015 at 07:40 AM -1
Share

If your original purpose is to view logs on devices, I recommend you use plugin "Device Console".

It's quite good.

Details: https://www.assetstore.unity3d.com/#!/content/44935

3 Replies

· Add your reply
  • Sort: 
avatar image
10
Best Answer

Answer by Tetrad · Mar 02, 2010 at 05:34 PM

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.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image burnumd · Mar 02, 2010 at 07:05 PM 4
Share

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.

avatar image Andre Galastri · Mar 04, 2010 at 11:45 AM 0
Share

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.

avatar image volk · Nov 28, 2011 at 06:57 PM 1
Share

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

avatar image OLP · Nov 26, 2013 at 07:36 PM 0
Share

Unity seems to support only 1 LogCallback at a time. There's probably another place in your code (or in a plugin) that overwrite your registration. Calling it everyframe ensures your callback is always the latest registered.

avatar image
2

Answer by jonas-echterhoff · Feb 15, 2010 at 09:09 AM

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Andre Galastri · Feb 17, 2010 at 06:53 PM 0
Share

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

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

avatar image
1

Answer by Fernando Zapata 1 · Jun 18, 2010 at 11:57 PM

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Unhiding Duplicated Logging Statements 1 Answer

what is the output log in the game data 1 Answer

Trace error with line number in device platform 0 Answers

How to redirect System.Console.Write from dll to Debug.Log 1 Answer

Redirect log to console / don't rewrite log file 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges