Enhance the Debug class with numerous improvements that can greatly improve readability in the Console and save a lot of time by enabling more compact debugging code to be used.
This is a plug & play solution; all Debug commands in your classes will automatically switch to using the new and improved versions.
Asset Store - Buy Debug.Log Extensions
Webpage - Find the blog, contact information…
Online Documentation - Scripting reference
Features
Clean Console
Stack traces are no longer visible for every entry in the Console list. This greatly improves readability.
Syntax Highlighting
Your console messages are automatically augmented with colorful syntax highlighting, improving readability even more.
Automatic Context
The context Object is automatically determined for your messages whenever possible to help with locating message sources.
Channels
Organize messages into channels (like Audio
, AI
…) and make the Console window only display messages from the ones you care about.
Debug.Log(()=>field)
A new compact syntax can be used to log both the name and value of a field to the console.
Debug.LogChanges(()=>field)
Have messages be printed automatically whenever the value of a field changes.
Debug.LogState(target)
Easily print the full state of a target to the console.
Debug.DisplayOnScreen(()=>field)
Easily display the name and current value of any field on the screen.
Debug.LogToFile(message, path)
Easily output messages into text files instead of the console.
Dev.Log(message)
Just like Debug.Log except all calls are omitted from release builds.
Critical.Log(message)
Useful for important messages you don’t want getting lost in the shuffle; uses a larger font, full stack trace and always gets recorded in a log file, regardless of Project Settings.
Highly Customizable
Thorough customization options allow you to configure everything to fit your team as well as your personal preferences.
Console+
An augmented Console window with controls for filtering messages based on their channels, the ability to locate all instances of types references in stack traces, and more.
Usage
Before:
Debug.Log(nameof(target)+"="+(target == null ? "null" : target.name), this);
After:
Debug.Log(()=>target);
Console:
target="Player"
Before:
var message = "MyClass state:\n"
+ "speed=" + speed + "\n";
+ "target=" + (target == null ? "null" : target.name) + "\n";
+ "progress=" + progress;
...
Debug.Log(message, this);
After:
Debug.LogState(this);
Console:
MyClass state:
speed=5
target=null
progress=0.25
Before:
int lastValue;
void Update()
{
if(myField != lastValue)
{
Debug.Log("myField="+(lastValue = myField)+"\n(was: "+lastValue+")", this);
lastValue = myField;
}
}
After:
Debug.LogChanges(()=>myField);
Console:
----------------------------------------------------------
myField=5
(was: 4)
----------------------------------------------------------
myField=6
(was: 5)
----------------------------------------------------------
Installation
When you import the Debug.Log Extensions package to a project, a dialog will appear asking you whether you’d like to replace all usages of the built-in Debug class with the extended Debug class, or if you’d prefer to opt-in to use it on a script-by-script basis.
You can change this choice later by going to Project Settings > Debug.Log Extensions
.
Unique Namespace
If you choose to install the extended Debug class in a unique namespace, then all your existing classes will continue using the built-in UnityEngine.Debug class by default, and you can switch individual scripts to use the extended Debug class with a using alias:
using UnityEngine;
using Debug = Sisus.Debugging.Debug; // <- opt-in to use extended Debug class
class Player : MonoBehaviour
{
void Awake()
{
var greeting = "Hello, World!";
Debug.Log(()=> greeting);
}
Global Namespace
If you install the extended Debug class in the global namespace, then all your classes will use the extended Debug class by default, and you won’t need to add any using aliases to them:
using UnityEngine;
class Player : MonoBehaviour
{
void Awake()
{
var greeting = "Hello, World!";
Debug.Log(()=> greeting);
}
Resolving Conflicts
There is an edge case in which the compile might not know if usages of Debug
are supposed to refer to the extended class in the global namespace or the built-in one, and that is if a script has created a using alias with the identifier Debug
:
using UnityEngine;
using Debug = UnityEngine.Debug; // <- problem
class Player : MonoBehaviour
{
void Awake() => Debug.Log("Hello?"); // <- error CS0576: Namespace '<global namespace>' contains a definition conflicting with alias 'Debug'
}
To fix this just remove the using alias from the script. It’s not necessary when you have Debug.Log Extensions installed in the global namespace.
Assembly References
To make your script assembly reference the Debug.Log Extensions assembly, do the following:
- Select the Assembly Definition Asset for the assembly (create it if it doesn’t exist yet).
- Tick the
Override References
checkbox. - Add
Debug-Log-Extensions.dll
to theAssembly References
list. - Click
Apply
.