Expand description
Request logging for trillium.
Logger is a Handler that emits one line per request. Add it to a handler tuple ahead of
the handlers whose work you want to time and observe:
use trillium_logger::logger;
let handler = (logger(), "hello");Out of the box it uses dev_formatter, a compact colorized development format. To customize
the line, hand Logger::with_formatter a format built from the components in formatters.
§The log_format! macro
log_format! builds a formatter from a format_args!-style string. Bare {name}
placeholders refer to the building blocks in formatters; literal text between them is
emitted verbatim:
use trillium_logger::{Logger, log_format};
Logger::new().with_formatter(log_format!("{method} {url} -> {status}"));Anything that isn’t a bare built-in — a formatter that takes arguments, a closure, a value from
your own crate — is supplied as a named or positional argument, exactly as in format_args!:
use trillium::KnownHeaderName::UserAgent;
use trillium_logger::{Logger, formatters::request_header, log_format};
Logger::new().with_formatter(log_format!(
"{ip} \"{method} {url}\" {status} {ua}",
ua = request_header(UserAgent),
));The macro expands to the same composable LogFormatter tuples you can also build by hand; see
that trait for the lower-level interface and for writing your own components.
Re-exports§
pub use crate::formatters::apache_combined;pub use crate::formatters::apache_common;pub use crate::formatters::dev_formatter;
Modules§
- client
client - Request/response logging for
trillium-client. - formatters
- Components with which common log formats can be constructed
Macros§
- log_
format - Build a server-side log formatter from a
format_args!-style string.
Structs§
- LogTarget
- An easily-named
Arc<dyn Targetable>that is stored in trillium shared state - Logger
- The trillium handler for this crate, and the core type
Enums§
- Color
Mode - A configuration option that determines if format will be colorful.
- Target
- Specifies where the logger output should be sent
Traits§
- LogFormatter
- The interface to format a &
Connas aDisplay-able output - Targetable
- A trait for log targets. Implemented for
Targetand for allFn(String) + Send + Sync + 'static.
Functions§
- logger
- Convenience alias for
Logger::new