Search Unity

Player log file location changed; is there an option in settings somewhere to change it back?

Discussion in 'Editor & General Support' started by Dreamback, Oct 20, 2017.

  1. Dreamback

    Dreamback

    Joined:
    Jul 29, 2016
    Posts:
    220
    In Unity 2017.2, in Windows the log file is now located in

    C:\Users\username\AppData\Local\CompanyName\ProductName\output_log.txt

    when it used to be in the Product_Data folder. And that makes sense for release builds, but is there an option to return this to the old location while testing? The problem is, if I make two builds of my game with different filenames or locations (a very common thing in testing), they now write their logs to the exact same place, overwriting each other. I see you can manually set a path with a command-line parameter, but that would be a real pain to have to do that every time I made a build with a new name.
     
  2. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    476
    it's now fairly easy to send
    all of the log file to somewhere else ...


    Code (CSharp):
    1.  
    2. using UnityEngine;
    3.  
    4. public class LogAnywhere : MonoBehaviour
    5. {
    6.     string filename = "";
    7.     void OnEnable() { Application.logMessageReceived += Log;  }
    8.     void OnDisable() { Application.logMessageReceived -= Log; }
    9.  
    10.     public void Log(string logString, string stackTrace, LogType type)
    11.     {
    12.         if (filename == "")
    13.         {
    14.             string d = System.Environment.GetFolderPath(
    15.               System.Environment.SpecialFolder.Desktop) + "/YOUR_LOGS";
    16.             System.IO.Directory.CreateDirectory(d);
    17.             filename = d + "/my_happy_log.txt";
    18.         }
    19.  
    20.         try {
    21.             System.IO.File.AppendAllText(filename, logString + "\n");
    22.         }
    23.         catch { }
    24.     }
    25. }
    26.  
    Fortunately it's that easy
     
    skabed, xano_saga, dmzl and 6 others like this.
  3. adityakaishav

    adityakaishav

    Joined:
    Jan 16, 2019
    Posts:
    27
    Code (CSharp):
    1.  
    Code (CSharp):
    1. void Awake()
    2. {
    3.      Application.logMessageReceived += onLogMessageReceived;
    4. }
    5. void onLogMessageReceived(string logString, string stackTrace, LogType type)
    6. {
    7.      output = logString;
    8.      stack = stackTrace;
    9.      log_type = type;
    10.      if (log_type == LogType.Error || log_type == LogType.Exception)
    11.      {
    12.             writeReportInFile();   // Saves log in a file
    13.      }
    14. }
    Hi @Fattie
    I am using above code to save logs in case of Exceptions, Errors etc, at run time in the game. So my question is, is onLogMessageReceived() method also gets called when crash happens or can we also save logs in case of crash (if app gets crashed at run time)? and does it also catches StackOverFlowExceptions? Please let me know. Thanks in advance.
     
    Last edited: Aug 26, 2021
  4. Fattie

    Fattie

    Joined:
    Jul 5, 2012
    Posts:
    476
    hi Adi. when including code in your posts, please format it as code. you can click edit, select the code, and click the "code format" button in the bar and save

    the code sample I gave will pipe exactly what normally goes "to the log"

    About your question I have no idea. Give it a try and see. It would likely depend on the type of crash. Try dividing by zero etc to force a crash. Best of luck
     
  5. adityakaishav

    adityakaishav

    Joined:
    Jan 16, 2019
    Posts:
    27
    Hi @Fattie Thanks for the reply and correcting me about code formatting. Okay I will try that.