exlab_wizard.plugins.logger#

Plugin logger shim. Backend Spec §6.1.4 / §6.3.2.

Plugins call ctx.log.info(...) / ctx.log.warning(...) rather than print() or logging.getLogger(...) directly because:

  1. In the worker subprocess (the production path), stdout is reserved for the IPC envelope – a stray print corrupts the protocol. Stderr carries structured log frames the host re-emits into the wizard log.

  2. In-process invocations (unit tests, --no-isolation debug) need a logger that forwards into the canonical exlab_wizard.logging.get_logger() chain so log records show up alongside everything else.

The PluginLogger base type is the abstract surface plugins see; the two implementations – HostPluginLogger (in-process) and WorkerPluginLogger (subprocess) – share the same four-method shape (debug / info / warning / error).

Each call accepts a positional message and arbitrary structured **fields keyword args; the host logger renders them as key=value extras while the worker logger emits them inside the JSON frame’s context block (which the host then merges back in). Plugin authors do not need to know which path they’re on – the API is identical.

Classes

HostPluginLogger([name])

In-process forwarder used when plugins run without subprocess isolation.

PluginLogFrame(level, message, context, ...)

Wire format for worker-side log records.

PluginLogger()

Abstract structured-log interface plugins receive on ctx.log.

WorkerPluginLogger([stream])

Worker-side forwarder.

class exlab_wizard.plugins.logger.HostPluginLogger(name='exlab_wizard.plugins')[source]#

Bases: PluginLogger

In-process forwarder used when plugins run without subprocess isolation.

Used by the host’s unit-test shim, by --no-isolation debug invocations of the plugin CLI (Backend Spec §6.10), and by the host when re-emitting parsed worker frames. Routes through exlab_wizard.logging.get_logger() so records flow into the canonical handler chain (per-equipment file, central rotating, stderr).

Parameters:

name (str)

debug(message, **fields)[source]#

Emit a DEBUG-level structured log record.

Parameters:
Return type:

None

error(message, **fields)[source]#

Emit an ERROR-level structured log record.

Parameters:
Return type:

None

info(message, **fields)[source]#

Emit an INFO-level structured log record.

Parameters:
Return type:

None

warning(message, **fields)[source]#

Emit a WARNING-level structured log record.

Parameters:
Return type:

None

class exlab_wizard.plugins.logger.PluginLogFrame(level: str, message: str, context: dict[str, ~typing.Any]=<factory>)[source]#

Bases: Struct

Wire format for worker-side log records.

The worker subprocess emits one PluginLogFrame-shaped JSON object per log line on its stderr stream; the host parses each line and forwards into the canonical logger chain. Backend Spec §6.3.2.

context: dict[str, Any]#
level: str#
message: str#
class exlab_wizard.plugins.logger.PluginLogger[source]#

Bases: ABC

Abstract structured-log interface plugins receive on ctx.log.

Implementations forward to either the in-process stdlib logger (HostPluginLogger) or the worker stderr channel (WorkerPluginLogger). Both expose the same four-method shape; plugin authors should not reach behind it.

abstractmethod debug(message, **fields)[source]#

Emit a DEBUG-level structured log record.

Parameters:
Return type:

None

abstractmethod error(message, **fields)[source]#

Emit an ERROR-level structured log record.

Parameters:
Return type:

None

abstractmethod info(message, **fields)[source]#

Emit an INFO-level structured log record.

Parameters:
Return type:

None

abstractmethod warning(message, **fields)[source]#

Emit a WARNING-level structured log record.

Parameters:
Return type:

None

class exlab_wizard.plugins.logger.WorkerPluginLogger(stream=None)[source]#

Bases: PluginLogger

Worker-side forwarder. Emits JSON frames on stderr.

Used inside the plugin worker subprocess (Backend Spec §6.3.1). Each call serializes a PluginLogFrame via msgspec.json and writes a single newline-terminated line to the configured stream (defaults to sys.stderr). The host reads these line-by-line and forwards them to the canonical logger.

The worker MUST NOT use stdout for log output – that channel is reserved for the IPC envelope. Stderr is the structured-log sideband.

Parameters:

stream (Optional[IO[str]])

debug(message, **fields)[source]#

Emit a DEBUG-level structured log record.

Parameters:
Return type:

None

error(message, **fields)[source]#

Emit an ERROR-level structured log record.

Parameters:
Return type:

None

info(message, **fields)[source]#

Emit an INFO-level structured log record.

Parameters:
Return type:

None

warning(message, **fields)[source]#

Emit a WARNING-level structured log record.

Parameters:
Return type:

None