Emitter Module API Reference¶
This section documents the internals of the emitter
module in Bijux CLI.
bijux_cli.infra.emitter ¶
Provides the concrete implementation of the structured output emitter service.
This module defines the Emitter
class, which implements the EmitterProtocol
. It is responsible for serializing data payloads into structured formats like JSON or YAML and writing them to standard output or a specified file. The service also integrates with telemetry to log emission events.
Emitter ¶
Emitter(
telemetry: TelemetryProtocol,
output_format: OutputFormat = JSON,
debug: bool = False,
quiet: bool = False,
**kwargs: Any,
)
Bases: EmitterProtocol
A service for serializing and emitting structured output.
This class implements the EmitterProtocol
. It handles the serialization of data payloads and writes the result to standard output or a file, while also tracking events with a telemetry service.
Attributes:
-
_telemetry
(TelemetryProtocol
) –The telemetry service for event tracking.
-
_default_format
(OutputFormat
) –The default format for serialization.
-
_debug
(bool
) –Flag indicating if debug mode is enabled.
-
_quiet
(bool
) –Flag indicating if normal output should be suppressed.
-
_logger
–A configured
structlog
logger instance.
Initializes the Emitter service.
Parameters:
-
telemetry
(TelemetryProtocol
) –The telemetry service for event tracking.
-
output_format
(OutputFormat
, default:JSON
) –The default output format for emissions.
-
debug
(bool
, default:False
) –If True, enables debug logging.
-
quiet
(bool
, default:False
) –If True, suppresses all non-error output.
-
**kwargs
(Any
, default:{}
) –Additional keyword arguments (unused).
Source code in src/bijux_cli/infra/emitter.py
emit ¶
emit(
payload: Any,
*,
fmt: OutputFormat | None = None,
pretty: bool = False,
level: str = "info",
message: str = "Emitting output",
output: str | None = None,
**context: Any,
) -> None
Serializes and emits a structured data payload.
The payload is serialized to the specified format and written to stdout or a file path if provided. The operation is suppressed if the emitter is in quiet mode and the log level is not critical.
Parameters:
-
payload
(Any
) –The data payload to serialize and emit.
-
fmt
(OutputFormat | None
, default:None
) –The output format. If None, the service's default format is used.
-
pretty
(bool
, default:False
) –If True, formats the output for human readability.
-
level
(str
, default:'info'
) –The log level for any accompanying message (e.g., "info", "debug", "error").
-
message
(str
, default:'Emitting output'
) –A descriptive message for logging purposes.
-
output
(str | None
, default:None
) –An optional file path to write the output to. If None, output is written to
sys.stdout
. -
**context
(Any
, default:{}
) –Additional key-value pairs for structured logging.
Returns:
-
None
(None
) –
Raises:
-
CommandError
–If the payload cannot be serialized.