NoaConsoleLog
Through this class, you can obtain logs held by the ConsoleLog feature.
APIs
Static Methods
API | Description |
---|---|
Add(LogType, message, stackTrace) | Adds a log to be output to the ConsoleLog tool. If stackTrace is not specified, it automatically retrieves the stack trace. |
Clear() | Deletes all stored log information at once. |
Static Properties
API | Description |
---|---|
LogList | Returns a list of the log information it retains. |
OnError | This is an event that runs when an error is detected. |
OnFilterErrorNotification | This is a delegate that determines whether to display notifications when an error is detected. It will display notifications if it returns true. Please refer to the sample code for specific usage. |
OnLogCopied | This event is triggered when a log is copied to the clipboard. |
OnLogDownload | This event is triggered when a log is downloaded. If the event handler returns true, the logs will be downloaded locally. If the event handler returns false, the logs will not be downloaded. Note: When registering this event, the OnLogDownloadWithLogEntries event will be unregistered. |
OnLogDownloadWithLogEntries | This event is triggered when a log is downloaded. If the event handler returns true, the logs will be downloaded locally. If the event handler returns false, the logs will not be downloaded. Note: When registering this event, the OnLogDownload event will be unregistered. |
OnLogSend | This event is triggered when a log is sent. It fires when the [ |
Sample Code
using System.Collections.Generic;
using System.Threading.Tasks;
using UnityEngine;
#if NOA_DEBUGGER
using NoaDebugger;
#endif
public class Example
{
void ExampleMethod()
{
#if NOA_DEBUGGER
// Get a list of log information retained by the ConsoleLog function.
LinkedList<ConsoleLogEntry> consoleLogList = NoaConsoleLog.LogList;
// Add logs to the ConsoleLog function.
NoaConsoleLog.Add(UnityEngine.LogType.Error, "log_message", "log_stacktrace");
// Add logs to the ConsoleLog function (without stack trace).
NoaConsoleLog.Add(UnityEngine.LogType.Error, "log_message");
// Add logs from a background thread.
Task.Run(() => NoaConsoleLog.Add(UnityEngine.LogType.Error, "log_message"));
// Set an event to be executed when an error is detected.
NoaConsoleLog.OnError += (ConsoleLogEntry log) => Debug.Log("Error detected.");
// Set a delegate to determine whether to display notifications when an error is detected.
NoaConsoleLog.OnFilterErrorNotification += (ConsoleLogEntry log) => log.LogString.StartsWith("Log to notify an error.");
// Set up the event that is triggered when a log is copied to the clipboard.
NoaConsoleLog.OnLogCopied += (ConsoleLogEntry log, string clipboardText) => Debug.Log($"Log copied. Clipboard: {clipboardText}");
// Set up the event that is triggered when a log is downloaded.
NoaConsoleLog.OnLogDownload += (string filename, string jsonData) =>
{
Debug.Log($"Logs download. Filename: {filename}");
// Return true to allow local download.
// Return false to prevent local download.
return true;
};
// Set up the event that is triggered when a log is downloaded.(To retrieve log information)
NoaConsoleLog.OnLogDownloadWithLogEntries += (string filename, List<ConsoleLogEntry> logList) =>
{
Debug.Log($"Logs download. Filename: {filename}");
// Return true to allow local download.
// Return false to prevent local download.
return true;
};
// Set up the event that is triggered when a log is sent.
NoaConsoleLog.OnLogSend += (List<ConsoleLogEntry> logList) => Debug.Log("Log sent.");
// Delete all logs.
NoaConsoleLog.Clear();
#endif
}
}