A TADS3 module for syslog(3)-ish message logging for debugging

Here’s a TADS3/adv3 module that implements a syslog-ish interface for logging debugging information: syslog github repo.

It’s basically a slightly more ornate version of debugging-via-printf(), but lacking a proper interactive debugger for T3 I find myself using it a lot. Dunno how useful it will be to anyone else.

Basic usage is just to use the Syslog class as a mixin on classes/objects. You can then use _debug(msg) to write msg to output via aioSay().

The two main advantages (as I see it) over just directly outputting stuff are:

  • All debugging output can be toggled on and off via the -D SYSLOG flag at compile time
  • You can supply optional flags on the logged messages, and enable/disable individual flags to control what’s output at runtime

Flags are arbitrary strings (so they’re actually more like tags). Simple example:

class Foozle: Thing, Syslog
        syslogID = 'FoozleStuff'
        someMethod() {
                _debug('this space intentionally left blank', 'testflag');
        }
;

local obj = new Foozle();

// No output;  "testflag" is not set.
obj.someMethod();

// Set "testflag"
syslog.enable('testflag');

// Now this will output "FoozleStuff: this space intentionally left blank"
obj.someMethod();

// Unset "testflag"
syslog.disable('testflag');

// No output again
obj.someMethod();

It’s all dead simple and is only around a hundred lines of code in total (including comments). But I’ve re-implemented it in slightly different forms a couple times now. So I figured it probably should be its own thing in a single place. In particular as I wade into the depths of NPC scripting I’ve been using the ability to toggle specific classes of debugging output on and off.

3 Likes