Skip to main content

Module logging

Module logging 

Source
Expand description

Structured logging configuration.

Ported from internal/logging (config.go, logger.go) and internal/logging/cliflags (flags.go). This crate uses tracing/tracing-subscriber as the idiomatic Rust equivalent of Go’s log/slog + tint (see PORT_NOTES.md).

new_logger/new_logger_with_writer install a small hand-rolled [tracing::Subscriber] (see the private format submodule) rather than tracing_subscriber::fmt’s built-in formatter, because the ported tests assert on the exact abbreviated level tags ("INF"/"WRN") and ANSI colouring tint produces in the Go original – tracing_subscriber::fmt’s default formatter spells levels out in full ("INFO"/"WARN") and has no built-in "source" field, neither of which the ported assertions would tolerate.

Re-exports§

pub use config::Config;
pub use config::Format;
pub use config::Output;

Modules§

cliflags
CLI flag definitions for the logging package.
config
Logging configuration.

Enums§

LoggerError
Ported from ErrUnsupportedFormat.

Functions§

is_terminal
Ported from isTerminal. Go checks whether the underlying io.Writer is backed by a real TTY (via golang.org/x/term.IsTerminal on the file descriptor); a Vec<u8> buffer or other non-fd-backed writer is never a terminal.
new_logger
Ported from NewLogger. Returns the writer’s Drop/close handle alongside the logger, mirroring Go’s io.Closer return value.
new_logger_with_writer
Ported from NewLoggerWithWriter. Unlike new_logger, the caller already owns w and is responsible for flushing/closing it; this function only wraps it in the same shared, lockable handle LoggerSubscriber needs to be usable concurrently with any other clone of the returned dispatch.