Skip to content

Log Methods

Yamastu edited this page Dec 1, 2017 · 4 revisions

Sys.Log

Method within UnityEngine.Sys class

public static void Log(string message)

public static void Log(string message, bool showInConsole)

Description

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).

PARAMETERS:
message - the debug message to be displayed in the exported Sys.Log file.
showInConsole - if true, the Sys.Log message will also be passed to the console via Debug.Log method.
USEAGE:
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);
    }

}

Sys.ClearLog

Method within UnityEngine.Sys class

public static void ClearLog()

Description

Clears the log cache and wipes list data.

USEAGE:
using System.Collections;
using UnityEngine;
...
    void Start () {
        //This clears all messages in the log data list.
        Sys.ClearLog();
    }

}

Sys.SaveLog

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).

PARAMETERS:
path - desired path to save the Sys.Log as a text file.
openDirectory - if true, File Explorer will open the containing folder of your saved file (Desktop Only).
USEAGE:
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");
    }

}

Clone this wiki locally