pub struct Setup { /* private fields */ }Expand description
Builder for the tracing-subscriber config.
All knobs are optional with sensible defaults. Build up the config and
call install when done.
Implementations§
Source§impl Setup
impl Setup
Sourcepub fn new() -> Self
pub fn new() -> Self
New builder with defaults: pretty format, "info,sqlx=warn" filter,
no thread IDs, no line numbers, targets shown.
Sourcepub fn json(self) -> Self
pub fn json(self) -> Self
Output JSON instead of pretty colored format. Recommended for production (Loki / CloudWatch / Datadog all parse JSON).
Sourcepub fn with_default_env_filter(self, filter: impl Into<String>) -> Self
pub fn with_default_env_filter(self, filter: impl Into<String>) -> Self
Default env-filter when RUST_LOG is unset. Defaults to
"info,sqlx=warn".
Sourcepub fn without_targets(self) -> Self
pub fn without_targets(self) -> Self
Hide event targets (the module path) in pretty output.
Sourcepub fn with_thread_ids(self) -> Self
pub fn with_thread_ids(self) -> Self
Include thread IDs in events.
Sourcepub fn with_line_numbers(self) -> Self
pub fn with_line_numbers(self) -> Self
Include source-file line numbers in events. Useful in dev, noisy in prod.
Sourcepub fn with_file(
self,
dir: impl Into<PathBuf>,
filename_prefix: impl Into<String>,
rotation: Rotation,
) -> Self
pub fn with_file( self, dir: impl Into<PathBuf>, filename_prefix: impl Into<String>, rotation: Rotation, ) -> Self
Tee logs to a rolling file in dir/filename_prefix.YYYY-MM-DD
in addition to stdout. By default rotates daily; pass a
different Rotation to override. The directory is created on
first write if it doesn’t exist.
File output uses tracing-appender’s non-blocking writer so a
stalled disk doesn’t pause request handling — events queue
in-memory and drop only under sustained extreme pressure.
Closes future-backlog item #1 (“advanced logging config”).
use rustango::logging::{Setup, Rotation};
Setup::new()
.json()
.with_file("/var/log/myapp", "app", Rotation::Daily)
.install();Sourcepub fn file_only(self) -> Self
pub fn file_only(self) -> Self
When Self::with_file is configured, drop the stdout layer
so logs land in the rolling file ONLY. No-op when no file
sink is configured.
Sourcepub fn install(self) -> Option<WorkerGuard>
pub fn install(self) -> Option<WorkerGuard>
Apply the config. Uses try_init under the hood — duplicate calls
are silently ignored. When Self::with_file is configured,
returns the tracing_appender::WorkerGuard that flushes
pending writes on drop — keep it alive for the lifetime of the
process (typically by stashing in a static or OnceLock).
None is returned when no file sink is configured.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Setup
impl RefUnwindSafe for Setup
impl Send for Setup
impl Sync for Setup
impl Unpin for Setup
impl UnsafeUnpin for Setup
impl UnwindSafe for Setup
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more