Unity Community

Register or Sign In:

+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 20 of 21

  1. Posts
    7

    Debug.Log and needless spam :]

    Please take a look at the following picture:



    I think that you'll all agree that the UnityEngine.Debug:Log(Object) is appended under every log statement, is not needed - doesn't make the programmer's life easier, doesn't help with finding bugs or telling anything important. It's making the log show twice less info than it could and increases visual clutter.

    Having used UE3, which has the simplest logger ever - `log("statement"); just prints the 'statement', without any line number, time&date info or anything else, I'm pretty disappointed by Unity's logger.

    If there's a need to distinguish between different log messages types, it's enough to change the icon (like it's already done) and if there's really a need to show UnityEngine.Debug:Log(Object) then it can be done in the small place below console, where you see the full text of message (and it's already shown there too).That's a good place for it.

    But please remove it from the main log (or at least give the option of disabling it)! I think it shouldn't be hard :] rather quick and easy change, that will improve the usability of console and whole unity platform a lot.


    Thank you.


  2. Location
    California, USA
    Posts
    88
    You could override Unity's Debug class with your own. I've done this in the past.

    Code:  
    1. using UnityEngine;
    2.  
    3. class Debug : UnityEngine.Debug
    4. {
    5.     private static string hr = "\n\n-------------------------------------------------------------------------------";
    6.  
    7.     public static new void Log(object message)
    8.     {
    9.         UnityEngine.Debug.Log(message.ToString() + hr);
    10.     }
    11.  
    12.     public static new void Log(object message, Object context)
    13.     {
    14.         UnityEngine.Debug.Log(message.ToString() + hr, context);
    15.     }
    16.  
    17.     public static new void LogError(object message)
    18.     {
    19.         UnityEngine.Debug.LogError(message.ToString() + hr);
    20.     }
    21.  
    22.     public static new void LogError(object message, Object context)
    23.     {
    24.         UnityEngine.Debug.LogError(message.ToString() + hr, context);
    25.     }
    26.  
    27.     public static new void LogWarning(object message)
    28.     {
    29.         UnityEngine.Debug.LogWarning(message.ToString() + hr);
    30.     }
    31.  
    32.     public static new void LogWarning(object message, Object context)
    33.     {
    34.         UnityEngine.Debug.LogWarning(message.ToString() + hr, context);
    35.     }
    36. }

    Does the Unity Debug class get removed on release builds?

    When Unity iPhone apps are built for release on the AppStore, are the Debug messages usually present, or does Xcode remove them automatically?
    Michael Ryan
    » something STRANGE


  3. Posts
    7
    Erm, why would I do that?

    Instead of getting ie.

    "WALKING ON SURFACE blablabla
    UnityEngine.Debug:Log(Object)"

    in your implementation I would be getting:

    "WALKING ON SURFACE blablabla

    ----------------------------------------
    UnityEngine.Debug:Log(Object)"


    That would add even more to the unwanted spam. I don't need any more whitespaces or anything else... I just want to get rid of "UnityEngine.Debug:Log(Object)" ... or is there sth that I'm missing here?


  4. Location
    California, USA
    Posts
    88
    I'm not sure if you're aware of this, but every Unity Console message that is generated using Debug.Log includes stacktrace information that follows immediately after any custom message you specify.

    The Console just happens to show the first two lines of each message. Therefore, if you have a short message that takes up only one line, you will always see "UnityEngine.Debug:Log(Object)" directly beneath it.

    To get around that, you can manually append a newline character ("\n") after your message. Then you'll just see your custom message in the Console, because everything else will be cut off. Regardless, if you click on one of the Console items, you will see the full message in the area below.

    The code I provided earlier automatically adds the newline character, as well as a separator so it's easier to see where your portion of the log message ends, and the stacktrace begins.
    Michael Ryan
    » something STRANGE


  5. Location
    London
    Posts
    1,033
    Does turning on the collapse option help?


  6. Posts
    7
    mryan: oh I see now what you meant. But I suspect that this approach makes the "UnityEngine.Debug:Log(Object)" text just pushed line below, so that it disappears from log, yet single element still has the same height and the whole list looks the same (minus the text, which makes it easier on the eyes which is good, but still not what I originally asked for).

    I don't know by myself, since I couldn't get it to work :/ ehhh noobish problem (I'm still new to unity): alongside other scripts, I made a new C# script file MyDebug, where I copied your code, renamed the class to MyDebug, and then tried using it in my
    javascript files:

    MyDebug.Log("WALKING ON SURFACE g: " + timeGrounded + " a: " + timeInAir );

    Unforunately I get "Unknown identifier: 'MyDebug'. " What's the way of "including" C# files in javascript and/or how to use this class ie do I have to define a static instance?


    monark: unfortunately collapse doesn't help


  7. Location
    California, USA
    Posts
    88
    See this page for information on mixing C# and Javascript:

    LINK: Overview: Script compilation (Advanced)

    I always use C#, but I just tried to duplicate what you were doing, and also received the error. Placing the C# script in the "Standard Assets" folder corrected the issue. The link above provides details on exactly how the engine compiles scripts.
    Michael Ryan
    » something STRANGE


  8. Posts
    126
    Hmm.. doesn't seem to work (anymore). I always get a
    Code:  
    1. cannot derive from sealed type `UnityEngine.Debug'

    Although my concern is that I want to get rid of the stacktrace, unless specifically asked for. When testing performance for iPhone, one single Debug line takes about 50 times as long to compute as the rest of the frame, so I have to remove all debug output every time I want to test performance.
    Quote Originally Posted by Shakespeare
    2b || !2b == theQuestion


  9. Posts
    56
    Bump. I'd like to get rid of the stacktrace too, as it is needless spam in the xcode debug log which is getting in the way of the real info that I want to see. Is there any way to do this?


  10. Posts
    1,609
    None that I know of if you are sending to the standard Unity Debug log window, but you can implement your own logging framework or use one of the many fine ones available. Implemented your own logging window and you're good to go.

    I use LoggingFramework which was a doddle to port to Unity. Gives me everything I need and I can turn logging on and off to the console as I desire.


  11. Location
    Montreal, Canada
    Posts
    1,437
    I kinda wish you could provide it with a Stack Trace. Or at least something useful so that when I double click the links I don't go to my define wrapped Asserts, but to the callee of those asserts.


  12. Posts
    56
    Thanks. How would one implement their own logging window? The only way to get debug output from Unity is via Debug.Log, right? So no matter what, your output is going to go via there in the end right? What does LoggingFramework do for you? Does it write to a file?

  13. zhx zhx is offline

    Posts
    535
    firstly, @JustinLloyd, pretty impressive you got LoggingFramework into Unity. Any possibility you'd be willing to share ;-)

    has anyone found a solution to strip all debug calls from an XCODE build, or preferably BEFORE Unity Builds the app itself, so they're stripped before the project goes into xcode? perhaps an asset in the asset store ;-).

    we're aware of the "Debug.isDebugBuild" approach, but would like to avoid it if possible.

    We've been searching for a solution that strips(thus sliences) ALL debug.log and debug.warning calls in our solution(we'd still like to be able to see logErrors, but would be willing to lose to too if the fix called for it). We haven't found any solutions. On and iPhone every cpu cycle is so precious, we'd love to have these debug.log/warning call's we've placed in our solution appear in the unity editor, but not be called at in the compiled app/ipa. That being said, we would happily lose ALL log messages if it would just prevent them from running when the app is on the (mobile) device. Its wild how much CPU time some log calls can take; yes we can manually silence them, but with a large solution, if we miss one or 2, its a timesink to have to go in and out and enable/disable them manually all the time :-(

    We'd greatly appreciate any help anyone can lend, as we started to think we were the only ones looking for such a solution(especially for mobiles).

    Thanks much for any help anyone can offer :-)
    Last edited by zhx; 09-16-2011 at 04:47 PM.
    all your neutron are belong to neutrinoless-double-beta-decay.... ;-)
    psimek.com


  14. Posts
    1,609
    How to port LoggingFramework to Unity:

    Purchase LoggingFramework for $5 http://www.theobjectguy.com/dotnetlog/Overview.aspx
    Create logger class in BitFactory.Logging namespace that wraps Debug.Log in a DoLog override function
    Compile to .NET DLL
    Copy .NET DLL to Unity project plugins directory
    Add using LoggingFramework to required .CS files
    Instantiate logger in game startup code
    Run

    I'm having a hard time thinking of any other steps I might have missed.

  15. zhx zhx is offline

    Posts
    535
    thanks for taking the time & walkthrough on installing LogginFramework, I was weary of the setup process, but no longer :-)

    also, found this GREAT solution to strip all debug call by stripping out the out with an override that responds to the isDebugBuild setting, soooo useful.

    http://answers.unity3d.com/questions...-in-build.html
    all your neutron are belong to neutrinoless-double-beta-decay.... ;-)
    psimek.com

  16. zhx zhx is offline

    Posts
    535
    thanks for taking the time & walkthrough on installing LogginFramework, I was weary of the setup process, but no longer :-)

    also, found this GREAT solution to strip all debug call by stripping out the out with an static overrid that responds to the isDebugBuild setting, soooo useful.

    http://answers.unity3d.com/questions...-in-build.html
    Last edited by zhx; 09-16-2011 at 07:46 PM.
    all your neutron are belong to neutrinoless-double-beta-decay.... ;-)
    psimek.com


  17. Posts
    56
    Right, but you're still going through Debug.Log though, so you'll still get the callstack in the xcode debug output window..

    I guess the only way to do it is to write your own native logging function and call into that.

  18. zhx zhx is offline

    Posts
    535
    this method TOTALLY works for me, does exactly what I wanted, muting debug messages completely on a platform-specific basis. I have it check to see if the game is being played in any platform other than the unityeditor, if so, I have an if statement on all debug low/warning/errors that only process the deug.log/warning/error if the isDebugBuild variable (on my custom Debug Override Class) is true or false. I opened xcode, used the device console and tested on multiple devices, no debug prints or processing of any debug calls(when I have the ovveride class enabled). its awesome(for us anyway!)

    first I do this on launch of application:
    Code:  
    1. [SIZE="3"]if (iPhoneSettings.model != "UnityEditor"){
    2.                  Debug.isDebugBuild = false; // ENABLE debug log messages in the Unity editor. if this is FALSE, which it is by default, NO debug messages would be displayed in the console or logged on the mobile(or desktop) device
    3.             }[/SIZE]

    then I create a new static Debug class to override the default unity debug class/processor. so AFAIK, and have been able to test, no more callstack logging(good for mobile devices, bad for unity editor ;-)).

    Code:  
    1. using UnityEngine;
    2. using System.Collections;
    3. using System;
    4. using System.IO;
    5. using System.Text.RegularExpressions;
    6. using UnityEngineInternal;
    7.  
    8. public static class Debug{
    9.     public static bool isDebugBuild = true;
    10.     //private static string hr = "\n\n-------------------------------------------------------------------------------";
    11.    
    12.    
    13.     public static new void Log (object message)
    14.     {   if (isDebugBuild)
    15.         UnityEngine.Debug.Log (message);
    16.         //UnityEngine.Debug.Log (message.ToString ());
    17.     }
    18.  
    19.     public static new void Log (object message, UnityEngine.Object context)
    20.     {   if (isDebugBuild)
    21.         UnityEngine.Debug.Log (message, context);
    22.         //UnityEngine.Debug.Log (message.ToString (), context);
    23.     }
    24.    
    25.    
    26.     public static new void LogError (object message)
    27.     {   if (isDebugBuild)
    28.         UnityEngine.Debug.LogError (message);
    29.         //UnityEngine.Debug.LogError (message.ToString ());
    30.     }
    31.  
    32.     public static new void LogError (object message, UnityEngine.Object context)
    33.     {   if (isDebugBuild)
    34.         UnityEngine.Debug.LogError (message, context);
    35.         //UnityEngine.Debug.LogError (message.ToString (), context);
    36.     }
    37.  
    38.     public static new void LogWarning (object message)
    39.     {   if (isDebugBuild)
    40.         UnityEngine.Debug.LogWarning (message.ToString ());
    41.     }
    42.  
    43.     public static new void LogWarning (object message, UnityEngine.Object context)
    44.     {   if (isDebugBuild)
    45.         UnityEngine.Debug.LogWarning (message.ToString (), context);
    46.     }
    47. }

    again, this works perfectly for us, no debug printing or processing of log calls of any sort from our app, no callstack processing(that we've been able to see like we used to), nothing. and actually we've gained a noticeable amount of cpu on iOS devices after this remedy.
    Last edited by zhx; 09-18-2011 at 06:38 PM.
    all your neutron are belong to neutrinoless-double-beta-decay.... ;-)
    psimek.com


  19. Posts
    56
    Doesn't do what I want, but thanks anyway (I wanted debug output without stack trace logging). I'll call into my own native log function.


  20. Posts
    186
    this is annoying, I like to remove the stack trace as I look at the log file for debugging