Debug.Log Extensions
Documentation (1.1.9)
Debug Class Reference

Description

Extended version of the built-in Debug class with additional methods to ease debugging while developing a game.

Static Properties

static bool UsePlayerLog [get]
 Reports whether messages logged using the Debug class are being recorded to a log file. More...
 
static bool developerConsoleVisible [get]
 Reports whether the development Console is visible. More...
 
static bool isDebugBuild [get]
 In the Build Settings dialog there is a check box called "Development Build". More...
 
static ILogger unityLogger [get]
 Gets the default debug logger used internally for logging all messages. More...
 

Log - Logs a message to the Console

static void Log ([CanBeNull]object message)
 Logs a message to the Console. More...
 
static void Log ([CanBeNull]object message, [CanBeNull]Object context)
 Logs a message to the Console. More...
 
static void Log (int channel, [CanBeNull]object message, [CanBeNull]Object context=null)
 Logs a message to the Console on the given channel . More...
 
static void Log (int channel1, int channel2, [CanBeNull]object message, [CanBeNull]Object context=null)
 Logs a message to the Console on the given channels. More...
 
static void Log ([CanBeNull]string message)
 Logs a message to the Console. More...
 
static void Log ([CanBeNull]string message, [CanBeNull]Object context)
 Logs a message to the Console. More...
 
static void Log (int channel, [CanBeNull]string message, Object context=null)
 Logs a message to the Console on the given channel . More...
 
static void Log (int channel1, int channel2, [CanBeNull]string message, Object context=null)
 Logs a message to the Console on the given channels. More...
 
static void Log ([CanBeNull]string message, [NotNull]Expression< Action > methodContext)
 Logs a message to the Console along with method signature on the second line to provide additional context. More...
 
static void Log ([NotNull]Expression< Func< object >> classMember, [NotNull]Expression< Action > methodContext)
 Logs to the Console the name and value of classMember class member along with method signature on the second line to provide additional context. More...
 
static void Log ([NotNull]Expression< Func< object >> classMember, [CanBeNull]Object context=null)
 Logs to the Console the name and value of classMember a class member. More...
 
static void Log (int channel, [NotNull]Expression< Func< object >> classMember, [CanBeNull]Object context=null)
 Logs to the Console on the given channel the name and value of classMember a class member. More...
 
static void Log ([NotNull]string prefix, [NotNull]params Expression< Func< object >>[] classMembers)
 Logs a message to the Console consisting of a prefix text string followed by the names and values of classMembers zero or more class members. More...
 
static void Log (params string[] messageParts)
 Logs a message to the Console formed by joining the given text strings together. More...
 
static void Log (string messagePart1, string messagePart2, params string[] messageParts)
 Logs a message to the Console formed by joining the given text strings together. More...
 
static void Log (object arg1, object arg2, params object[] args)
 Logs a message to the Console listing a number of elements separated by a separator character. More...
 
static void Log (string prefix, object arg, params object[] args)
 Logs a message to the Console consisting of a prefix text string followed by the values of args zero or more objects separated by a separator character. More...
 
static void Log (Object context, string part1, string part2, params string[] parts)
 Logs a message to the Console consisting of multiple parts joined together. More...
 
static void Log ([NotNull]params Expression< Func< object >>[] classMembers)
 Logs to the Console the name and value of one or more classMembers class members separated by a separator character. More...
 
static void Log (int channel, [NotNull]params Expression< Func< object >>[] classMembers)
 Logs to the Console on the given channel the name and value of zero or more classMembers class members separated by a separator character. More...
 
static void Log (int channel1, int channel2, [NotNull]params Expression< Func< object >>[] classMembers)
 Logs the name and value of one or more class members to the Console separated by a separator character using the given channels. More...
 

Log Format - Insert values into a message and log it to the Console

static void LogFormat (string format, params object[] args)
 Logs a message to the Console formed by inserting the values of args zero or more objects into a format text string. More...
 
static void LogFormat (Object context, string format, params object[] args)
 Logs a message to the Console formed by inserting the values of args zero or more objects into a format text string. More...
 
static void LogFormat (int channel, string format, params object[] args)
 Logs a message to the Console on the given channel , formed by inserting the values of args zero or more objects into a format text string. More...
 
static void LogFormat (int channel1, int channel2, string format, params object[] args)
 Logs a message to the Console on the given channels, formed by inserting the values of args zero or more objects into a format text string. More...
 
static void LogFormat (int channel1, int channel2, Object context, string format, params object[] args)
 Logs a message to the Console on the given channels, formed by inserting the values of args zero or more objects into a format text string. More...
 
static void LogFormat< LogOption > (LogType logType, LogOption logOptions, Object context, string format, params object[] args)
 Logs a message to the Console formed by inserting the values of args zero or more objects into a format text string. More...
 
static void LogFormat< LogOption > (int channel1, int channel2, LogType logType, LogOption logOptions, Object context, string format, params object[] args)
 Logs a message to the Console on the given channels, formed by inserting the values of args zero or more objects into a format text string. More...
 

Log State - Logs to the Console the name and value of every field and property of the target object

static void LogState ([CanBeNull]object target, BindingFlags flags=DefaultInstanceBindingFlags)
 Logs to the Console the name and value of every field and property of target matched using the specified flags . More...
 
static void LogState ([CanBeNull]object target, bool includePrivate, bool includeStatic=false)
 Logs to the Console the name and value of every field and property of target matched using the specified settings. More...
 
static void LogState ([NotNull]Type classType, BindingFlags flags=DefaultStaticBindingFlags)
 Logs to the Console the name and value of every static field and property of classType matched using the specified flags . More...
 

Log If - Logs a message to the Console only if a condition is true

static void LogIf (bool condition, string message, Object context=null)
 If condition is true logs a message to the Console. More...
 
static void LogIf (bool condition, int channel, string message, Object context=null)
 If condition is true logs to the Console on the given channel a message . More...
 
static void LogIf (bool condition, int channel, [NotNull] Expression< Func< object >> classMember, Object context=null)
 If condition is true logs to the Console on the given channel the name and value of classMember a class member. More...
 

Log Large - Logs a message to the Console using a large font size

static void LogLarge ([CanBeNull]string message, Object context=null)
 Logs a message to the Console using a large font size. More...
 
static void LogLarge (int channel, [CanBeNull]string message, Object context=null)
 Logs a message to the Console using a large font size and the given channel. More...
 
static void LogLarge (int channel1, int channel2, [CanBeNull]string message, Object context=null)
 Logs a message to the Console using a large font size and the given channels. More...
 

Log To File - Logs a message to a file

static void LogToFile (string message, [CanBeNull] string logFilePath=null, ClearFile clearFile=ClearFile.OnSessionStart)
 Appends a message to the end of the log file. More...
 
static void ClearLogFile (string path=null, bool backupExisting=true)
 Deletes existing log file at the given path created by a LogToFile call if one exists. More...
 

Log Changes - Logs to the Console the name and value of a class member any time its value is changed

static void LogChanges (Expression< Func< object >> classMember, bool pauseOnChanged=false)
 Logs to the Console the name and value of classMember any time its value is changed. More...
 
static void LogChanges ([CanBeNull]object memberOwner, [NotNull]MemberInfo classMember, bool pauseOnChanged=false)
 Logs to the Console the name and value of classMember any time its value is changed. More...
 
static void CancelLogChanges (Expression< Func< object >> classMember)
 Stop logging to the Console any time the value of classMember changes. More...
 
static void CancelLogChanges ([NotNull]MemberInfo classMember)
 Stop logging to the Console any time the value of classMember changes. More...
 
static void ClearTrackedValues ()
 Clears all value trackers that have been enabled using LogChanges. More...
 

Log Warning - Logs a warning message to the Console

static void LogWarning ([CanBeNull]object message)
 Logs a warning message to the Console. More...
 
static void LogWarning ([CanBeNull]object message, [CanBeNull]Object context)
 Logs a warning message to the Console. More...
 
static void LogWarning ([CanBeNull]string message)
 Logs a warning message to the Console. More...
 
static void LogWarning ([CanBeNull]string message, [CanBeNull]Object context)
 Logs a warning message to the Console. More...
 
static void LogWarning (int channel, [CanBeNull]string message, Object context=null)
 Logs a warning message to the Console on the given channel . More...
 
static void LogWarning (int channel1, int channel2, [CanBeNull]string message, Object context=null)
 Logs a warning message to the Console on the given channels. More...
 
static void LogWarning (object arg1, object arg2, params object[] args)
 Logs a warning message to the Console listing a number of elements separated by a separator character. More...
 
static void LogWarning (string prefix, object arg, params object[] args)
 Logs a warning message to the Console consisting of a prefix text string followed by the names and values of classMembers zero or more class members. More...
 
static void LogWarning (Object context, string part1, string part2, params string[] parts)
 Logs a warning message to the Console consisting of multiple parts joined together. More...
 
static void LogWarning ([NotNull]params Expression< Func< object >>[] classMembers)
 Logs a warning message to the Console consisting of the name and value of one or more class members separated by a separator character. More...
 
static void LogWarning ([NotNull]Expression< Func< object >> classMember, Object context=null)
 Logs a warning message consisting of the name and value of a class member to the Console. More...
 
static void LogWarning (int channel, [NotNull]Expression< Func< object >> classMember, Object context=null)
 Logs a warning message to the Console on the given channel and consisting of the name and value of a class member. More...
 
static void LogWarning (int channel1, int channel2, [NotNull]Expression< Func< object >> classMember, Object context=null)
 Logs a warning message consisting of the name and value of a class member to the Console. More...
 
static void LogWarning ([NotNull]string prefix, [NotNull]params Expression< Func< object >>[] classMembers)
 Logs a warning message to the Console consisting of a prefix text string followed by the names and values of classMembers zero or more class members. More...
 
static void LogWarning (string messagePart1, string messagePart2, params string[] messageParts)
 Logs a warning message to the Console formed by joining the given text strings together. More...
 
static void LogWarning (params string[] messageParts)
 Logs a warning message to the Console formed by joining the given text strings together. More...
 

Log Warning Format - Insert values into a message and log it to the Console as a warning

static void LogWarningFormat (string format, params object[] args)
 Logs a warning message to the Console formed by inserting the values of args zero or more objects into a format text string. More...
 
static void LogWarningFormat (Object context, string format, params object[] args)
 Logs a warning message to the Console formed by inserting the values of args zero or more objects into a format text string. More...
 
static void LogWarningFormat (int channel, Object context, string format, params object[] args)
 Logs a warning message to the Console formed by inserting the values of args zero or more objects into a format text string. More...
 
static void LogWarningFormat (int channel1, int channel2, Object context, string format, params object[] args)
 Logs a warning message to the Console formed by inserting the values of args zero or more objects into a format text string. More...
 
static void LogWarningFormat (int channel1, int channel2, string format, params object[] args)
 Logs a warning message to the Console formed by inserting the values of args zero or more objects into a format text string. More...
 

Log Warning Large - Logs a warning message to the Console using a large font size

static void LogWarningLarge ([CanBeNull]string message, Object context=null)
 Logs a warning message to the Console using a large font size. More...
 

Log Error - Logs an error message to the Console

static void LogError ([CanBeNull]string message)
 Logs an error message to the Console. More...
 
static void LogError ([CanBeNull]string message, [CanBeNull]Object context)
 Logs an error message to the Console. More...
 
static void LogError ([CanBeNull]object message)
 Logs an error message to the Console. More...
 
static void LogError ([CanBeNull]object message, [CanBeNull]Object context)
 Logs an error message to the Console. More...
 
static void LogError (int channel, [CanBeNull]string message, Object context=null)
 Logs an error message to the Console on the given channel . More...
 
static void LogError (int channel1, int channel2, [CanBeNull]string message, Object context=null)
 Logs an error message to the Console on the given channels. More...
 
static void LogError (object arg1, object arg2, params object[] args)
 Logs an error to the Console listing a number of elements separated by a separator character. More...
 
static void LogError (string prefix, object arg, params object[] args)
 Logs an error to the Console starting with prefix and followed by a list of elements separated by a separator character. More...
 
static void LogError (Object context, string part1, string part2, params string[] parts)
 Logs an error message to the Console consisting of multiple parts joined together. More...
 
static void LogError ([NotNull]params Expression< Func< object >>[] classMembers)
 Logs an error message to the Console consisting of the name and value of one or more class members separated by a separator character. More...
 
static void LogError (int channel, [NotNull]params Expression< Func< object >>[] classMembers)
 Logs an error message to the Console on the given channel and consisting of the name and value of one or more class members separated by a separator character. More...
 
static void LogError (int channel1, int channel2, [NotNull]params Expression< Func< object >>[] classMembers)
 Logs an error message to the Console on the given channels and consisting of the name and value of classMembers zero or more class members separated by a separator character. More...
 
static void LogError ([NotNull]Expression< Func< object >> classMember, Object context=null)
 Logs a warning message to the Console consisting of the name and value of classMember a class member. More...
 
static void LogError ([NotNull]string prefix, [NotNull]params Expression< Func< object >>[] classMembers)
 Logs an error message to the Console consisting of a prefix text string followed by the names and values of classMembers zero or more class members. More...
 
static void LogError (string messagePart1, string messagePart2, params string[] messageParts)
 Logs an error to the Console formed by joining the given text strings together. More...
 
static void LogError (params string[] messageParts)
 Logs an error to the Console formed by joining the given text strings together. More...
 

Log Error Format - Insert values into a message and log it to the Console as an error

static void LogErrorFormat (string format, params object[] args)
 Logs an error message to the Console formed by inserting the values of args zero or more objects into a format text string. More...
 
static void LogErrorFormat (Object context, string format, params object[] args)
 Logs an error message to the Console formed by inserting the values of args zero or more objects into a format text string. More...
 

Log Error Large - Logs an error message to the Console using a large font size

static void LogErrorLarge ([CanBeNull]string message, Object context=null)
 Logs an error message to the Console using a large font size. More...
 

Log Exception - Logs an exception to the Console

static void LogException (Exception exception)
 Logs an exception to the Console. More...
 
static void LogException (Exception exception, Object context)
 Logs an exception to the Console. More...
 
static void LogException (int channel, Exception exception, Object context=null)
 Logs an exception to the Console on the given channel . More...
 

Log Assertion - Logs an assertion message to the Console

static void LogAssertion (object message, Object context=null)
 Logs an assertion message to the Console. More...
 

Log Assertion Format - Insert values into a message and log it to the Console as an assertion

static void LogAssertionFormat (string format, params object[] args)
 Logs an assertion message to the Console formed by inserting the values of args zero or more objects into a format text string. More...
 
static void LogAssertionFormat (Object context, string format, params object[] args)
 

Assert - Logs an error to the Console if condition is not true

static void Assert (bool condition, int channel, Object context=null)
 Logs an error message to the Console if condition is not true. More...
 
static void Assert (bool condition, int channel1, int channel2, Object context=null)
 Logs an error message to the Console if condition is not true. More...
 
static void Assert (bool condition, Object context=null)
 Logs an error message to the Console if condition is not true. More...
 
static void Assert (bool condition, object message, Object context=null)
 Logs an error message to the Console if condition is not true. More...
 
static void Assert (bool condition, int channel, object message, Object context=null)
 Logs an error message to the Console if condition is not true. More...
 
static void Assert (bool condition, int channel1, int channel2, object message, Object context=null)
 Logs an error message to the Console if condition is not true. More...
 
static void Assert (Expression< Func< bool >> condition, [NotNull]Expression< Action > contextMethod)
 Logs an error message to the Console if expression does not return true. More...
 
static void Assert (bool condition, string message, [NotNull]Expression< Action > methodContext)
 Logs an error message to the Console if condition is not true. More...
 
static void Assert (bool condition, [NotNull]Expression< Action > methodContext)
 Logs an error message to the Console if condition is not true. More...
 
static void Assert ([CanBeNull]object expectedValue, [NotNull]Expression< Func< object >> classMember)
 Logs an error message to the Console if classMember value does not match expectedValue . More...
 
static void Assert ([NotNull]Expression< Func< object >> classMember, [CanBeNull]Object context=null)
 Logs an error message to the Console if classMember value is not true. More...
 

Assert Warning - Logs a warning to the Console if condition is not true

static void AssertWarning (bool condition, Object context=null)
 Logs a warning message to the Console if condition is not true. More...
 
static void AssertWarning (bool condition, object message, Object context=null)
 Logs a warning message to the Console if condition is not true. More...
 

Ensure - Logs an error to the Console if condition is false and returns condition result

static bool Ensure (bool condition, Object context=null)
 If condition is false logs to the Console an error message and returns false. More...
 
static bool Ensure (bool condition, int channel, Object context=null)
 If condition is false logs to the Console on the given channel an error message and returns false. More...
 
static bool Ensure (bool condition, int channel1, int channel2, Object context=null)
 If condition is false logs to the Console on the given channels an error message and returns false. More...
 
static bool Ensure (bool condition, string message, Object context=null)
 If condition is false logs to the Console an error message and returns false. More...
 
static bool Ensure (bool condition, int channel, string message, Object context=null)
 If condition is false logs to the Console on the given channel an error message and returns false. More...
 

Guard - Logs an error to the Console if condition is false and returns negation of condition result

static bool Guard (bool condition, Object context=null)
 If condition is false logs to the Console an error message and returns true. More...
 
static bool Guard (bool condition, int channel, Object context=null)
 If condition is false logs to the Console on the given channel an error message and returns true. More...
 
static bool Guard (bool condition, int channel1, int channel2, Object context=null)
 If condition is false logs to the Console on the given channels an error message and returns true. More...
 
static bool Guard (bool condition, string message, Object context=null)
 If condition is false logs to the Console an error message and returns true. More...
 
static void Guard< TException > (bool condition, params object[] exceptionArguments)
 If condition is false throws an exception of type TException . More...
 
static bool Guard (bool condition, int channel, string message, Object context=null)
 If condition is false logs to the Console on the given channel an error message and returns true. More...
 
static bool Guard (bool condition, int channel, params string[] messageParts)
 If condition is false logs to the Console on the given channel an error message formed by joining the given text strings together and returns true. More...
 
static bool Guard (bool condition, params string[] messageParts)
 If condition is false logs to the Console an error message formed by joining the given text strings together and returns true. More...
 
static bool Guard (bool condition, [NotNull]Expression< Func< object >> classMember, Object context=null)
 If condition is false logs to the Console an error message containing the name and value of classMember class member and returns true. More...
 
static bool Guard (bool condition, int channel, [NotNull]Expression< Func< object >> classMember, Object context=null)
 If condition is false logs to the Console on the given channel an error message containing the name and value of classMember class member and returns true. More...
 
static bool Guard (bool condition, [NotNull]Expression< Action > methodContext)
 Logs an error message to the Console if condition is not true and returns true if condition was false or false if it was not. More...
 

Display On Screen - Displays something on screen

static void DisplayOnScreen ([NotNull]Expression< Func< object >> classMember)
 Start displaying the name and value of the class member on screen. More...
 
static void DisplayOnScreen ([CanBeNull]object memberOwner, [NotNull]MemberInfo classMember)
 Start displaying the name and value of the class member on screen. More...
 
static void CancelDisplayOnScreen ([NotNull]Expression< Func< object >> classMember)
 Stop displaying the name and value of a class member on screen. More...
 
static void CancelDisplayOnScreen ([NotNull]MemberInfo classMember)
 Stop displaying the name and value of a class member on screen. More...
 
static void DisplayButton ([NotNull]Expression< Action > onClicked)
 Start displaying a button on screen which calls a method when clicked. More...
 
static void DisplayButton (string label, [NotNull]Action onClicked)
 Start displaying a button on screen which calls a method when clicked. More...
 
static void CancelDisplayButton ([NotNull]Expression< Action > onClicked)
 Stop displaying a button on screen. More...
 
static void CancelDisplayButton ([NotNull]string label)
 Stop displaying a button on screen. More...
 
static void ShowFps ()
 Start displaying frame rate on screen. More...
 
static void CancelShowFps ()
 Stop displaying frame rate on screen. More...
 
static void ClearDisplayedOnScreen ()
 Clears the screen from all GUI elements that have been added to it using DisplayOnScreen. More...
 

Channel - Control logging of messages on channels

static void EnableChannel ([NotNull]string channel)
 Enables logging of messages on the given channel channel. More...
 
static void DisableChannel ([NotNull]string channel)
 Disables logging of messages on the given channel channel. More...
 

Stopwatch - Accurately measure elapsed time

static void StartStopwatch ()
 Starts a new stopwatch counting upwards from zero. More...
 
static void StartStopwatch ([NotNull]string name)
 Starts a new stopwatch counting upwards from zero with the given name. More...
 
static void StartSubStopwatch ()
 Starts a new sub-stopwatch running under the stopwatch that was last started using StartStopwatch. More...
 
static void StartSubStopwatch ([NotNull]string name)
 Starts a new sub-stopwatch running under the stopwatch that was last started using StartStopwatch. More...
 
static void StartSubStopwatch ([NotNull]string parentName, [NotNull]string name)
 Starts a new sub-stopwatch running under a parent stopwatch. If main stopwatch by provided name does not exist yet one will be created. More...
 
static void FinishSubStopwatch ()
 Gets the last started stopwatch and finishes the sub-stopwatch inside it which was last started, still leaving the main stopwatch running. More...
 
static void FinishSubStopwatch ([NotNull]string parentName)
 Finishes a previously created sub-stopwatch, still leaving the main stopwatch running. Results are not logged at this point, only when you finish the main stopwatch. More...
 
static void FinishSubStopwatch ([NotNull]string parentName, [NotNull]string name)
 Finishes a previously created sub-stopwatch, still leaving the main stopwatch running. Results are not logged at this point, only when you finish the main stopwatch. More...
 
static void FinishStopwatch ()
 Logs results of the last created stopwatch and clears it. More...
 
static void FinishStopwatch ([NotNull]string name)
 Logs results of a previously created stopwatch and then clears it. More...
 
static void FinishAllStopwatches ()
 Logs results of a all previously created stopwatches and the clears them. More...
 

Log Hierarchy Path - Logs the full hierarchy path of a scene object

static void LogHierarchyPath ([CanBeNull]Transform transform)
 Logs the full hierarchy path of the given transform to the Console. More...
 
static void LogHierarchyPath ([CanBeNull]GameObject gameObject)
 Logs the full hierarchy path of the given transform to the Console. More...
 

Draw - Draws something on the screen

static void DrawLine (Vector3 start, Vector3 end)
 Draws a line between specified start and end points. More...
 
static void DrawLine (Vector3 start, Vector3 end, Color color, float duration=0f, bool depthTest=true)
 Draws a line between specified start and end points. More...
 
static void DrawRay (Vector3 start, Vector3 dir)
 Draws a line from start to start + dir in world coordinates. More...
 
static void DrawRay (Vector3 start, Vector3 dir, Color color, float duration=0f, bool depthTest=true)
 Draws a line from start to start + dir in world coordinates. More...
 

Break

static void Break ()
 Pauses the editor. More...
 

Clear Console

static void ClearDeveloperConsole ()
 Clears errors from the developer Console.

See also
developerConsoleVisible
More...
 
static void ClearEditorConsole ()
 Clears errors from the Console window in the editor. More...