Skip to main content

Crate trillium_logger

Crate trillium_logger 

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

clientclient
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§

ColorMode
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 &Conn as a Display-able output
Targetable
A trait for log targets. Implemented for Target and for all Fn(String) + Send + Sync + 'static.

Functions§

logger
Convenience alias for Logger::new