• 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
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
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

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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 order, or Awake vs Start issue? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges