pub struct CliEmitter<W: Write> { /* private fields */ }Expand description
Stateful emitter for finite structured CLI executions.
The output format and redaction policy are fixed when the emitter is created. Emitting after a terminal event, emitting a repeated terminal event, and writer failures all return explicit errors.
0.16 API: Accepts typed Event, provides semantic convenience methods, and supports per-log default field provider.
Implementations§
Source§impl<W: Write> CliEmitter<W>
impl<W: Write> CliEmitter<W>
Sourcepub fn new(writer: W, format: OutputFormat) -> Self
pub fn new(writer: W, format: OutputFormat) -> Self
Create a new CLI emitter with default output options.
Sourcepub fn with_options(
writer: W,
format: OutputFormat,
output_options: OutputOptions,
) -> Self
pub fn with_options( writer: W, format: OutputFormat, output_options: OutputOptions, ) -> Self
Create a new CLI emitter with custom output options.
Sourcepub fn with_strict_protocol(self) -> Self
pub fn with_strict_protocol(self) -> Self
Require the AFDATA recommended strict profile for every emitted event.
Sourcepub fn with_log_fields<F>(self, provider: F) -> Self
pub fn with_log_fields<F>(self, provider: F) -> Self
Set a provider for default log fields.
The provider is called for every log event (via emit_log or emit with kind:log). Its output is merged as extension fields; explicit call-site fields take precedence.
Sourcepub fn emit(&mut self, event: Event) -> Result<(), CliEmitterError>
pub fn emit(&mut self, event: Event) -> Result<(), CliEmitterError>
Emit a typed Event (unified entry for all event kinds).
Accepts only SDK-constructed Event; for dynamic JSON, use emit_validated_value.
Sourcepub fn emit_validated_value(
&mut self,
value: Value,
) -> Result<(), CliEmitterError>
pub fn emit_validated_value( &mut self, value: Value, ) -> Result<(), CliEmitterError>
Emit and validate dynamic JSON, then apply redaction/formatting/write.
Runs strict validation first, ensuring the dynamic JSON is safe.
Sourcepub fn emit_result(&mut self, payload: Value) -> Result<(), CliEmitterError>
pub fn emit_result(&mut self, payload: Value) -> Result<(), CliEmitterError>
Convenience: build and emit a result event.
Sourcepub fn emit_error(
&mut self,
code: &str,
message: &str,
) -> Result<(), CliEmitterError>
pub fn emit_error( &mut self, code: &str, message: &str, ) -> Result<(), CliEmitterError>
Convenience: build and emit an error event.
Sourcepub fn emit_progress(&mut self, message: &str) -> Result<(), CliEmitterError>
pub fn emit_progress(&mut self, message: &str) -> Result<(), CliEmitterError>
Convenience: build and emit a progress event.
Sourcepub fn emit_log(
&mut self,
level: LogLevel,
message: &str,
) -> Result<(), CliEmitterError>
pub fn emit_log( &mut self, level: LogLevel, message: &str, ) -> Result<(), CliEmitterError>
Convenience: build and emit a log event with default fields.
Applies log_fields_provider if configured; explicit fields take precedence.
Sourcepub fn into_inner(self) -> W
pub fn into_inner(self) -> W
Access the underlying writer.