Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by ExtremePowers · Jan 15, 2015 at 07:58 PM · debuglogoverride

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";
     } 
 }
 
Comment
Add comment
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

3 Replies

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

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.

Comment
Add comment · Show 9 · 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 ExtremePowers · Jan 15, 2015 at 08:18 PM 0
Share

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.

avatar image DanSuperGP · Jan 15, 2015 at 08:36 PM 0
Share

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

avatar image ExtremePowers · Jan 15, 2015 at 08:44 PM 0
Share

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.

avatar image ExtremePowers · Jan 15, 2015 at 08:47 PM 0
Share

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.

avatar image DanSuperGP · Jan 15, 2015 at 08:47 PM 0
Share

And your logs aren't getting called in OnDestroy?

Show more comments
avatar image
3

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)

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
avatar image
1

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 :)

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

27 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


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