x


Debug Wrapper Class

I'd like to create a class that wraps Debug.Log so I can enhance logging. To start, I created something very simple:

public static class Log
{
public static void Format(string format, params object[] args)
{
Debug.Log(string.Format(format, args));
}
}

The problem is, when the log message appears in the console, double clicking it will bring you to this classes Debug.Log statement rather than the actual code where Log.Format was called.

Anyone found a way around this? That is, a way to wrap Debug.Log such that when clicked in the console you're taken to the source line that called the wrapper, and not to the wrapper itself.

more ▼

asked Oct 13 '11 at 11:28 PM

mhardy gravatar image

mhardy
16 2 2 4

I've got the same issue - Anyone ?

Nov 14 '11 at 06:15 PM da_chinese

Same here. Anything?

Apr 30 '12 at 06:44 PM Yannik
(comments are locked)
10|3000 characters needed characters left

2 answers: sort newest
public static void Log(object format, params object[] paramList)
{
    System.Diagnostics.StackFrame f = stackTrace.GetFrame(2);

    string log = string.Format("[{3}.{4}] == ",
        f.GetFileName(),        
        f.GetFileLineNumber(),      // always reports 0
        f.GetFileColumnNumber(),    // always reports 0
        f.GetMethod().ReflectedType.Name,
        f.GetMethod().Name);

    // if the last parameter is a unity object, lets feed it in as the context 
    UnityEngine.Object newContext = null;
    if(paramList.Length > 0 && paramList[paramList.Length - 1] is UnityEngine.Object)
         newContext = paramList[paramList.Length - 1] as UnityEngine.Object;
    //UnityEngine.Object context = f.GetMethod().ReflectedType;
    if (format is string)
    {
        log += format as string;
        Debug.Log(string.Format(log, paramList), newContext);
    }
    else
    {
        log += format.ToString();
        UnityEngine.Debug.Log(log, newContext);
    }
}

This is the closest i've come to doing that exact thing. It when double clicking, it still takes you to the debug proxy but when you select them in the editor, it will flash the object that signaled the log statement.

more ▼

answered Jun 06 '12 at 01:35 PM

szi_johnr gravatar image

szi_johnr
0

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

answered Oct 13 '11 at 11:41 PM

DaveA gravatar image

DaveA
26.5k 151 171 256

Close. That does get me the file and line number. Still can't double click it in the console window and be taken directly to the line though.

Oct 14 '11 at 05:40 AM mhardy
(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:

x239
x11

asked: Oct 13 '11 at 11:28 PM

Seen: 829 times

Last Updated: Jun 06 '12 at 01:35 PM