Structured Task Logging
The built-in leveled logger — levels, namespaces, and a pluggable sink.
The built-in leveled logger — levels, namespaces, and a pluggable sink.
The SDK ships a tiny zero-dependency leveled logger. It writes to stderr by
default, so it never pollutes stdout (the CLI's --json output and piped data
stay clean). FlexiQ uses it internally; it is exported for your own use too.
import { createLogger } from "@byteveda/flexiq";
const log = createLogger("billing"); // tagged [flexiq:billing]
queue.task("charge", async (amount: number) => {
log.info("charging", { amount });
// ...
});debug < info < warn < error < silent. The threshold defaults to warn and is
read once from FLEXIQ_LOG_LEVEL; override it at runtime:
import { setLogLevel } from "@byteveda/flexiq";
setLogLevel("debug"); // global, immediateA message can be a string or a thunk that is only evaluated when the level passes the threshold — so expensive log lines cost nothing when filtered out:
log.debug(() => `payload=${JSON.stringify(bigObject)}`);Extra arguments are appended: Errors render their stack, objects are
JSON-stringified.
log.error("delivery failed", err, { webhookId });createLogger(ns) tags every line [flexiq:ns]; child() nests further:
const log = createLogger("worker"); // [flexiq:worker]
const poolLog = log.child("pool"); // [flexiq:worker:pool]Replace the output sink to route logs to a file, JSON transport, or a test buffer — globally and immediately:
import { setLogSink } from "@byteveda/flexiq";
setLogSink((level, line) => myTransport.write({ level, line }));