Log

A class for logging errors, warnings and information! Different levels of information can be filtered out, and supports coloration via <~[colorCode]> and <~clr> tags.

Text colors can be set with a tag, and reset back to default with <~clr>. Color codes are as follows:

Dark Bright Decription
DARK BRIGHT DESCRIPTION
blk BLK Black
red RED Red
grn GRN Green
ylw YLW Yellow
blu BLU Blue
mag MAG Magenta
cyn cyn Cyan
grn GRN Green
wht WHT White

Static Fields and Properties

   
LogLevel Filter What’s the lowest level of severity logs to display on the console? Default is LogLevel.Info.

Static Methods

   
Err Writes a formatted line to the log using a LogLevel.Error severity level!
Info Writes a formatted line to the log using a LogLevel.Info severity level!
Subscribe Allows you to listen in on log events! Any callback subscribed here will be called when something is logged. This does honor the Log.Filter, so filtered logs will not be received here.
Unsubscribe If you subscribed to the log callback, you can unsubscribe that callback here!
Warn Writes a formatted line to the log using a LogLevel.Warn severity level!
Write Writes a formatted line to the log with the specified severity level!

Examples

An in-application log window

Here’s an example of using the Log.Subscribe method to build a simple logging window. This can be pretty handy to have around somewhere in your application!

Here’s the code for the window, and log tracking.

static Pose         logPose = new Pose(0, -0.1f, 0.5f, Quat.LookDir(Vec3.Forward));
static List<string> logList = new List<string>();
static void OnLog(LogLevel level, string text)
{
    if (logList.Count > 10)
        logList.RemoveAt(logList.Count - 1);
    logList.Insert(0, text.Length < 100 ? text : text.Substring(0,100)+"...");
}
static void LogWindow()
{
    UI.WindowBegin("Log", ref logPose, new Vec2(40, 0) * U.cm);
    for (int i = 0; i < logList.Count; i++)
        UI.Label(logList[i], false);
    UI.WindowEnd();
}

Then you add the OnLog method into the log events like this in your initialization code!

Log.Subscribe(OnLog);

And in your Update loop, you can draw the window.

LogWindow();

And that’s it!