Skip to main content

Console

Struct Console 

Source
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>

Source

pub fn with_format(self, format: OutputFormat) -> Self

Select text, JSON, or automatic output.

Source

pub fn with_ansi(self, enabled: bool) -> Self

Enable or disable ANSI colour in text output. JSON never includes styling.

Source

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.

Source

pub fn with_filter(self, filter: EnvFilter) -> Self

Set the console’s filter without affecting other subscriber layers.

Source

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>

Source

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.

Source

pub fn subscriber(self) -> impl Subscriber + Send + Sync

Build an isolated subscriber; no global state is installed.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Default for Console

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<W = Stderr> !Freeze for Console<W>

§

impl<W> RefUnwindSafe for Console<W>
where W: RefUnwindSafe,

§

impl<W> Send for Console<W>
where W: Send,

§

impl<W> Sync for Console<W>
where W: Sync,

§

impl<W> Unpin for Console<W>
where W: Unpin,

§

impl<W> UnsafeUnpin for Console<W>
where W: UnsafeUnpin,

§

impl<W> UnwindSafe for Console<W>
where W: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more