Skip to content

UXLogMonitor

UXLogMonitor is one registration on a UXLog: a pattern to watch for and a callback to call.

#use <UXKit> // or #import "UXLog.xc"
class UXLogMonitor : Object {
UXRegex* pattern;
callback cb void(u8* msg);
}

addMonitor makes one; you do not construct it.

A callback never owns its receiver. A monitor therefore cannot keep its observer alive, and a log watcher registered by a window does not keep that window in memory.

When the observer is freed, the callback reads false, the monitor is skipped, and nothing crashes. removeMonitor is therefore not needed as a crash guard or as teardown. Call it to stop watching while the observer is still alive.

The pattern is a shared UXRegex, compiled once when the monitor was added. Each message costs a match, not a compile, however many messages go past. One pattern object can serve several monitors.

The monitor calls pattern.test(msg), so the pattern has to occur somewhere in the message; it does not have to describe all of it. A monitor for "timeout" fires on "read timeout after 30s".

UXValidator’s regex rule works the other way: it uses matches and must describe the entire field. Both use the same engine. A log pattern anchored with ^…$ will almost never fire.

UXRegex* pattern // null is skipped, not treated as "match everything"

If compile was given an invalid pattern, the monitor is inert rather than firing on every line. A broken pattern that produced a flood would be worse than one that produces nothing. If a monitor never fires, check isValid.

compile never returns a null regex object, so a null pattern here means null was passed on purpose.

removeMonitor matches on the callback, not the pattern. If the same callback is registered twice with different patterns, you cannot choose which to remove; the first match goes.

For a watcher that needs several patterns under individual control, give each pattern its own method.

UXRegex* pattern

Held strongly, and shareable between monitors.

callback cb void(u8* msg)

Receives the message that matched. The message is the logger’s u8*, valid for the duration of the call. Copy it with UXStr.dup to keep it.