pub struct Console<W = Stderr> { /* private fields */ }Expand description
Configure console output without selecting a runtime or installing global state.
The default filter is info. Use Self::with_env_filter to read RUST_LOG, or Self::with_filter for explicit configuration. Writing is synchronous; complete records are serialized through the writer’s mutex.
Implementations§
Source§impl<W> Console<W>
impl<W> Console<W>
Sourcepub fn with_format(self, format: OutputFormat) -> Self
pub fn with_format(self, format: OutputFormat) -> Self
Select text, JSON, or automatic output.
Sourcepub fn with_ansi(self, enabled: bool) -> Self
pub fn with_ansi(self, enabled: bool) -> Self
Enable or disable ANSI colour in text output. JSON never includes styling.
Sourcepub fn with_writer<T>(self, writer: T) -> Console<T>
pub fn with_writer<T>(self, writer: T) -> Console<T>
Replace the destination. Automatic output treats custom writers as redirected streams, selecting JSON without colour. Use Self::with_format to request text.
Sourcepub fn with_filter(self, filter: EnvFilter) -> Self
pub fn with_filter(self, filter: EnvFilter) -> Self
Set the console’s filter without affecting other subscriber layers.
Sourcepub fn with_env_filter(self) -> Result<Self, FromEnvError>
pub fn with_env_filter(self) -> Result<Self, FromEnvError>
Read RUST_LOG, defaulting to info if absent. Invalid values are errors.
Source§impl<W: Write + Send + 'static> Console<W>
impl<W: Write + Send + 'static> Console<W>
Sourcepub fn layer<S>(self) -> impl Layer<S>where
S: Subscriber + for<'lookup> LookupSpan<'lookup>,
pub fn layer<S>(self) -> impl Layer<S>where
S: Subscriber + for<'lookup> LookupSpan<'lookup>,
Build a composable output layer, including support for captured span traces.
This does not install a subscriber or a log bridge. Its filter applies only to this layer. Attach it to a registry, then use a scoped subscriber or install the application’s combined subscriber.
Sourcepub fn subscriber(self) -> impl Subscriber + Send + Sync
pub fn subscriber(self) -> impl Subscriber + Send + Sync
Build an isolated subscriber; no global state is installed.
Sourcepub fn init(self)
pub fn init(self)
Install this console globally. Use Self::try_init to handle setup errors.
This leaves the process’s log logger unchanged.
§Panics
Panics if another global subscriber is already installed.
Sourcepub fn try_init(self) -> Result<(), SetGlobalDefaultError>
pub fn try_init(self) -> Result<(), SetGlobalDefaultError>
Try to install this console globally. Returns an error if another subscriber is already installed.
This leaves the process’s log logger unchanged. Applications that want to route log records into tracing can install tracing_log::LogTracer separately.