Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Preserve Logs Between Runs

Discussion in 'Editor & General Support' started by not_a_valid_username, Aug 2, 2018.

  1. not_a_valid_username

    not_a_valid_username

    Joined:
    Jul 28, 2018
    Posts:
    23
    I'm currently doing a lot of beta testing, and I am frequently using output logs from my beta testers to diagnose issues. Sometimes the tester will re-run the program before copying over the output log, which causes the original output log to be overwritten.

    Is it possible to make the output log use a new filename between runs? This way I could compare the logs between different runs without risk of the original issue being overwritten.
     
  2. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    You have a few options.

    1) Subscribe to the
    Application.logMessageReceived
    event. Unity will still create the output.log file with no changes, but now you can also do something additional with each log entry, such as output it to another file you create using System.IO.

    https://docs.unity3d.com/ScriptReference/Application-logMessageReceived.html
    https://docs.unity3d.com/ScriptReference/Application-logMessageReceivedThreaded.html
    https://docs.unity3d.com/ScriptReference/Application.LogCallback.html


    2) Create a class that implements the ILogHandler interface. You can then set
    Debug.unityLogger.logHandler = <yourLogger>
    , or you can call
    <yourLogger>.Log("Log Message")
    when you would normally call
    Debug.Log("Log Message")
    . I ran into issues with this and found method 1 to be more resistant to bugs messing up your logging.

    https://docs.unity3d.com/ScriptReference/ILogHandler.html


    You will still have to make sure you create a new log file with a unique filename for each run. I recommend using a timestamp in the filename.

    Best of luck!
     
  3. not_a_valid_username

    not_a_valid_username

    Joined:
    Jul 28, 2018
    Posts:
    23
    I think that'll work, thanks for the help!
     
  4. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    You could also create a launcher for your game that first copies the old log to a new location (or even uploads it to a server of yours) before launching the game.

    Alternatively the launcher app could launch your game with a custom logfile parameter so log files don't overwrite.
     
  5. EyePD

    EyePD

    Joined:
    Feb 26, 2016
    Posts:
    63
    A custom launcher with the command line option to name the file works but it's extra baggage that needs to be packaged and ultimately the user could still click on the main executable directly (especially if that's what they're already used to doing with an existing app). It would be great if there could be an option in the player settings to allow control over the naming and allow for text substitutions so for example you could put in an "YYYYMMDDHHSS" type of date format so the logs would never be overwritten.
     
  6. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    You can set a listener for the event
    Application.logMessageReceivedThreaded
    . I have a logging script that runs on a program that runs for weeks at a time. Every 24 hours or 10k log entries, I end the current file and start a new one using System.IO, and I output any log entries I get from the
    Application.logMessageReceivedThreaded
    event into the newest log file.
     
    EyePD likes this.
  7. am_GA

    am_GA

    Joined:
    Oct 4, 2018
    Posts:
    20
    @Gambit-MSplitz possible for you to share the script, so we don't have to reinvent the wheel? Would be greatly appreciated.
     
  8. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    I would if I could, but I'm afraid it's property of the company I work for, and it hooks into some of our other proprietary systems anyway. Sorry =(