-
Notifications
You must be signed in to change notification settings - Fork 1
Log Methods
Method within UnityEngine.Sys class
public static void Log(string message)
public static void Log(string message, bool showInConsole)
Sends a user defined debug message to a list that can be exported to a text file. (See SaveLog() for more information.) All messages passed through the Sys.Log method are time stamped in the [MMDDYYHHMMSS] format. When showInConsole is true, the message will be displayed in the console (via Unity's 'Debug.Log' method).
showInConsole - if true, the Sys.Log message will also be passed to the console via Debug.Log method.
using System.Collections;
using UnityEngine;
public class LogExample : MonoBehaviour {
void Start () {
//This will not show the message in console, but will save the log to log file.
Sys.Log("This is a test!");
//However this will show your message in console and save to .log file
Sys.Log("This is a test!" , true);
}
}
Method within UnityEngine.Sys class
public static void ClearLog()
Clears the log cache and wipes list data.
using System.Collections;
using UnityEngine;
...
void Start () {
//This clears all messages in the log data list.
Sys.ClearLog();
}
}
Method within UnityEngine.Sys class
public static void SaveLog()
public static void SaveLog(string path)
public static void SaveLog(string path, bool openDirectory)
This method saves log data to a specified path. If no path is specified, data is saved to the default location: {PersistentDataPath}/{ProjectName}/Logs/SysLog.txt
. This is the case when SaveLog();
is called.
If the log data should be saved to a different location, using SaveLog("Path/To/Your/LogFile.txt");
. Also using SaveLog("Path/To/Your/LogFile.txt", true);
will open your log's directory upon file save (Windows Only).
openDirectory - if true, File Explorer will open the containing folder of your saved file (Desktop Only).
using System.Collections;
using UnityEngine;
public class LogExample : MonoBehaviour {
void Start () {
//Checking if directory exists, if not it will be created See DirectoryCheck() for more information.
if(Sys.DirectoryCheck("Path_To_Log_File/SysLog.txt",true)){
//Checking if file exists, if not it will be created. See FileCheck() for more information.
Sys.FileCheck("Path_To_Log_File/SysLog.txt", true);
}
//This saves the default 'SysLog.txt' file to {PersistentDataPath}/{ProjectName}/Logs/SysLog.txt
Sys.SaveLog();
//This allows you to save your log to any given directory.
Sys.SaveLog("Path_To_Log_File/SysLog.txt");
//However this will allow you to save your log to any given directory, and open the directory in File Explorer.
Sys.SaveLog("Path_To_Log_File/SysLog.txt");
}
}