Logging
Logging that says which behaviour, which method and which line it came from, and keeps working after upload.
Udon has no call stack. A helper handed a string cannot find out who called it, and a world's log is a flat stream from every behaviour at once, so Debug.Log("done") is a line nobody can trace back to a file.
Udonite Logging attaches the answer at the call site:
using Udonite.Logging;
public class Scoreboard : UdoniteBehaviour
{
public override void Start()
{
Log.Info("ready");
}
public void Award(int points)
{
Log.Assert(points > 0);
Log.Info("awarding " + points, "scoring");
}
}
[Scoreboard.Start:7] ready
[assertion failed] [Scoreboard.Award:14] points > 0
[scoring] [Scoreboard.Award:16] awarding -3
It costs nothing. [CallerFilePath], [CallerMemberName] and [CallerLineNumber] are substituted by the C# compiler while it binds the call, so by the time a world runs they are constants that were written into the program. There is no lookup, no reflection, and nothing per frame.
What is in it
| Call | Writes |
|---|---|
Log.Info(message) |
an ordinary line |
Log.Warning(message) |
a warning |
Log.Error(message) |
an error |
Log.Assert(condition) |
an error quoting the condition, only when it is false |
Log.Entry(message) |
a LogEntry object instead of a written line |
Log.Site() |
the [Type.Member:line] prefix alone |
Every one of them takes an optional tag, which groups related lines without inventing a prefix by hand.
The Console keeps working after upload
The Unity Console goes blind the moment a world leaves the Editor. After that the only record is a log file with thousands of lines of the client talking to itself.
Udonite → Open Window → Settings → Logging reads that file and puts your lines back in the Console, exactly as they read in play mode, so the same window keeps working in a real world with real players in it.
Where to go next
Getting started is the whole of the logging API, and what each part of a line means.
World logs is the Editor half: watching a running world from the Console, and what to do when a behaviour faults and switches itself off.