Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Timestamped Debug logging

Discussion in 'Wish List' started by akotranza, Sep 22, 2011.

  1. akotranza

    akotranza

    Joined:
    Sep 7, 2011
    Posts:
    36
    Would be great for all Debug.Log variants to have the option of printing a timestamp (w/ inclusion of a couple of typical DateTime.ToString formats as consts).

    i.e.

    void Log(object message, TimestampFormat format)

    TimestampFormat ->
    const .HHMMSSMS
    const .HHMMSS
    etc
    static .FromString(...)
     
    nick-morhun and EyePD like this.
  2. Ntero

    Ntero

    Joined:
    Apr 29, 2010
    Posts:
    1,436
    Why not just make your own logs:
    Code (csharp):
    1.  
    2. public static void MyLog(string message)
    3. {
    4. Debug.Log(message + "\n" + DateTime.Now.ToString());
    5. }
    6.  
    If you wrap the logs in your own custom calls you can even add category logs, and log levels and data shown toggles(like stack trace or custom error code enumerations)
     
  3. akotranza

    akotranza

    Joined:
    Sep 7, 2011
    Posts:
    36
    Why not post in the *wish list* section a feature I *wish* they'd include in the core functionality?

    Already implemented what I pasted above, thanks :)
     
  4. akotranza

    akotranza

    Joined:
    Sep 7, 2011
    Posts:
    36
    All snark aside, there is a very legit reason why the wrapper approach sucks.

    With the wrapper, double clicking the log entry in the Console just takes you to your wrapper code, vs. taking you to the line where you initiated the Log entry. With wrapper code you have to look at the Console entry's stack trace and find the method and line manually. This takes minimum 10 sec (and scales with size of codebase!) vs. double clicking the Console entry and being taken there automatically in 0.5 sec. (roughly const w/ size of codebase!). If you do this 50 times in the course of an 8 hour day, you waste 8 minutes because you had to wrap the logging code. Every day!

    So, yeah, Unity guys, please make this a core feature.
     
    EyePD likes this.
  5. Ntero

    Ntero

    Joined:
    Apr 29, 2010
    Posts:
    1,436
    This I 100% agree with that issue. Though before they enter in TimeStamps I would suggest they implement a way to add in custom StackTraces. So that all custom logging utilities can just add new StackTrace(1).

    We currently use custom logging to create our own Assert class, so that we don't perform calculations we don't have to, or log what is not relevant at release. I do find that losing the 'click to find line' is a significant loss. There are lots of reasons to use Custom Logging functions and it'd be nice to be able to redirect to where the log actually takes you.
     
  6. akotranza

    akotranza

    Joined:
    Sep 7, 2011
    Posts:
    36
    That would also be a good feature to have!
     
  7. bdev

    bdev

    Joined:
    Jan 4, 2011
    Posts:
    656
    I think in a lot of cases just the order in which stuff logs is enough. Adding a time stamp is tricky because some things like FixedUpdate if your running slow it will do two calls to FixedUpdate with only one call to update. Where Time.time in each fixed update call changes. And you'd have to ask yourself do i want it stamped with Time.time ? or Time.realtimeSinceStartup? or System.DateTime.Now?

    But at the same time i don't think your asking for a lot, and i don't see any reason why it couldn't be a option.