Skip to main content

Debug

A static class in Root.Township, the global namespace.

The game's own global Debug class, which hides UnityEngine.Debug in the game code. Sets up NLog logging on first use and sends Unity's log output and these calls through NLog.

Fields​

MemberWhat it is
static string LogConfigPathPath of the NLog config file in use. Defaults to StreamingAssets/NLog.config unless /logging_config_path is given.
7 private and internal fields
MemberWhat it is
private static string commandLinePathCached /logging_config_path value, empty if not given.
private static ILogHandler defaultUnityLoggerUnity's original log handler, saved before the game replaces it.
private static bool isSetupTrue once SetupLogging has run.
private static string logBasePathBase log folder used by the logpath layout renderer. Changed by UpdateLogFolderPath.
private static readonly Logger loggerNLog logger that the Log methods write to.
private static readonly Logger unhandledExceptionsLoggerNLog logger named UnhandledExceptions, for exceptions Unity logs.
private static readonly Logger unhandledLoggerNLog logger named Unhandled, for other Unity log messages.

Properties​

MemberWhat it is
static bool isDebugBuild { get; }Always false.
static string LogFolderPath { get; private set; }The log folder as worked out from the NLog config's logFolderPath variable.

Methods​

MemberWhat it is
static void Assert(bool condition, string errorMessage = "Assert Failed", Object context = null)Logs the error message if the condition is false. Doesn't throw or break.
static void Break()Does nothing.
static void DrawLine(Vector3 start, Vector3 end, Color color)Draws a debug line through Unity's Debug.DrawLine.
static void Log(object message, Object context = null)Logs the message at Info level.
static void LogError(object message, Object context = null)Logs the message at Error level.
static void LogErrorFormat(string format, params object[] args)Logs a formatted message at Error level.
static void LogException(Exception exception, Object context = null)Logs the exception and its message at Error level.
static void LogFormat(string format, params object[] args)Logs a formatted message at Info level.
static void LogWarning(object message, Object context = null)Logs the message at Warn level.
static void LogWarningFormat(string format, params object[] args)Logs a formatted message at Warn level.
static void SetupLogging()Loads the NLog config, registers the game's targets and layout renderers and takes over Unity's log handler. Runs once.
static void UpdateLogFolderPath(string newLogFolder)Changes the base log folder and reloads the NLog config.
16 private and internal methods
MemberWhat it is
private static void AddCsvTargetWithName(LoggingConfiguration config, CsvLayout csvLayout, string name)Adds an async CSV file target under Logs in the persistent data folder, archiving at 10 MB and keeping 20 archives.
private static void AddCustomTarget(LoggingConfiguration config, string fileName, params string[] fields)Adds a CSV target with time, level, logger and the given event property columns.
private static void AddCustomTargetsAndRenderers()Registers the game's NLog targets (Unity console, server console, console commands, main menu) and layout renderers such as logpath and entity-id.
private static void AddErrorTarget(LoggingConfiguration config)Adds the ErrorLogFile CSV target with message, stack trace and exception columns.
private static void AddSimpleTarget(LoggingConfiguration config, string fileName)Adds a CSV target with time, level, logger and message columns.
private static void AddSuperSimpleTarget(LoggingConfiguration config, string fileName)Adds a CSV target with only time and message columns.
private static string GetLogFolderPath()Base log folder: the data folder on a server, the client folder otherwise, or the folder of -logFile if given.
private static string GetLogSettingsPath()Returns the /logging_config_path value, or an empty string. The cached empty string means the GameConfig fallback is never reached.
private static void LoadConfiguration()Loads the NLog config and reconfigures existing loggers, logging to Unity if it fails.
private static void LogManagerConfigurationReloaded(object sender, LoggingConfigurationReloadedEventArgs e)Logs a line when NLog reloads its configuration.
private static void SetFullLogFolderPath()Sets LogFolderPath from the logFolderPath variable in the loaded NLog config.
private static void SetupForAndroid()Builds an NLog config in code for Android with Unity console and CSV file targets. Not called in this file.
private static void SetupForStandalone()Loads NLog config from the settings path or StreamingAssets/NLog.config, and hooks Unity's threaded log messages.
private static void SetupHostname()Sets the server_name and hostname NLog context values from the HOSTNAME variable, or agones-server.
private static void ShutdownNLog()Flushes and shuts down NLog. Runs last on application quit.
private static void UnhandledUnityLog(string condition, string stackTrace, LogType type)Forwards Unity log messages to NLog: exceptions to the UnhandledExceptions logger, everything else as warnings to Unhandled.