pub struct LoggingConfig { /* private fields */ }Expand description
Typed configuration for Nidus logging helpers.
LoggingConfig builds tracing-subscriber subscribers and structured
service/request spans. It does not install HTTP middleware by itself; pair it
with tower_http::trace::TraceLayer and StructuredMakeSpan for request
spans.
use nidus_http::logging::{LoggingConfig, StructuredMakeSpan};
use tower_http::trace::TraceLayer;
let logging = LoggingConfig::production("users-api")
.version("1.2.3")
.environment("production")
.level_filter("info,tower_http=debug")
.redact_header("authorization");
logging.init()?;
let trace_layer = TraceLayer::new_for_http()
.make_span_with(StructuredMakeSpan::new(logging));Implementations§
Source§impl LoggingConfig
impl LoggingConfig
Sourcepub fn production(service_name: impl Into<String>) -> Self
pub fn production(service_name: impl Into<String>) -> Self
Creates production JSON logging config for a service.
Defaults to JSON output, info filtering, and no redacted headers.
Sourcepub fn development(service_name: impl Into<String>) -> Self
pub fn development(service_name: impl Into<String>) -> Self
Creates development pretty logging config for a service.
This keeps the same service metadata defaults as production but uses pretty text formatting.
Sourcepub fn service_name(&self) -> &str
pub fn service_name(&self) -> &str
Returns the service name.
Sourcepub fn version(self, version: impl Into<String>) -> Self
pub fn version(self, version: impl Into<String>) -> Self
Sets the service version.
The version is included in Self::service_span and
StructuredMakeSpan fields.
Sourcepub fn environment(self, environment: impl Into<String>) -> Self
pub fn environment(self, environment: impl Into<String>) -> Self
Sets the deployment environment.
The environment is included in Self::service_span and
StructuredMakeSpan fields.
Sourcepub fn with_format(self, format: LoggingFormat) -> Self
pub fn with_format(self, format: LoggingFormat) -> Self
Sets the logging format.
Sourcepub fn level_filter(self, level_filter: impl Into<String>) -> Self
pub fn level_filter(self, level_filter: impl Into<String>) -> Self
Sets the tracing level filter directive.
Sourcepub fn redact_header(self, header: impl AsRef<str>) -> Self
pub fn redact_header(self, header: impl AsRef<str>) -> Self
Marks a header as redacted for application log code.
This stores redaction policy for callers via Self::redacts_header.
The built-in StructuredMakeSpan does not log arbitrary request
headers, so there is no automatic header scrubber to install.
Sourcepub fn redacts_header(&self, header: impl AsRef<str>) -> bool
pub fn redacts_header(&self, header: impl AsRef<str>) -> bool
Returns whether the config redacts a header name.
Sourcepub const fn output_format(&self) -> LoggingFormat
pub const fn output_format(&self) -> LoggingFormat
Returns the configured output format.
Sourcepub const fn format(&self) -> LoggingFormat
pub const fn format(&self) -> LoggingFormat
Returns the configured output format.
Sourcepub fn service_span(&self) -> Span
pub fn service_span(&self) -> Span
Creates a root service span carrying stable deployment attributes.
Sourcepub fn init(&self) -> Result<(), TryInitError>
pub fn init(&self) -> Result<(), TryInitError>
Installs this config as the process-global tracing subscriber.
Like other tracing-subscriber global installs, this usually succeeds
once per process. Tests often prefer Self::subscriber_with_writer to
avoid global state.
Sourcepub fn subscriber_with_writer<W>(
&self,
writer: W,
) -> impl Subscriber + Send + Sync + 'static
pub fn subscriber_with_writer<W>( &self, writer: W, ) -> impl Subscriber + Send + Sync + 'static
Builds a JSON subscriber using a caller-provided writer.
Sourcepub fn pretty_subscriber_with_writer<W>(
&self,
writer: W,
) -> impl Subscriber + Send + Sync + 'static
pub fn pretty_subscriber_with_writer<W>( &self, writer: W, ) -> impl Subscriber + Send + Sync + 'static
Builds a pretty subscriber using a caller-provided writer.
Trait Implementations§
Source§impl Clone for LoggingConfig
impl Clone for LoggingConfig
Source§fn clone(&self) -> LoggingConfig
fn clone(&self) -> LoggingConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more