pub struct Logger<F, S = StartFormatter> { /* private fields */ }Expand description
The trillium handler for this crate, and the core type
Implementations§
Source§impl Logger<()>
impl Logger<()>
Sourcepub fn new() -> Logger<DevFormatter>
pub fn new() -> Logger<DevFormatter>
Builds a new logger
Defaults:
- formatter:
DevFormatter - color mode:
ColorMode::Auto - target:
Target::Stdout - init message: true
- start logging: disabled (see
Logger::with_start_logging)
Source§impl<T, S> Logger<T, S>
impl<T, S> Logger<T, S>
Sourcepub fn with_formatter<Formatter: LogFormatter>(
self,
formatter: Formatter,
) -> Logger<Formatter, S>
pub fn with_formatter<Formatter: LogFormatter>( self, formatter: Formatter, ) -> Logger<Formatter, S>
replace the formatter with any type that implements LogFormatter
see the trait documentation for LogFormatter for more details. note that this can be
chained with Logger::with_target and Logger::with_color_mode
use trillium_logger::{Logger, apache_common};
Logger::new().with_formatter(apache_common("-", "-"));Sourcepub fn with_start_formatter<Formatter: LogFormatter>(
self,
start_formatter: Formatter,
) -> Logger<T, Formatter>
pub fn with_start_formatter<Formatter: LogFormatter>( self, start_formatter: Formatter, ) -> Logger<T, Formatter>
replace the request-start formatter, enabling start logging as if by
Logger::with_start_logging
Completion-oriented components like formatters::status and
formatters::response_time do not have meaningful values when the start line is
formatted, as no handlers have run yet.
use trillium_logger::{Logger, log_format};
Logger::new().with_start_formatter(log_format!("Started {method} {url}"));Source§impl<F, S> Logger<F, S>
impl<F, S> Logger<F, S>
Sourcepub fn with_color_mode(self, color_mode: ColorMode) -> Self
pub fn with_color_mode(self, color_mode: ColorMode) -> Self
specify the color mode for this logger.
see ColorMode for more details. note that this can be chained
with Logger::with_target and Logger::with_formatter
use trillium_logger::{ColorMode, Logger};
Logger::new().with_color_mode(ColorMode::On);Sourcepub fn with_target(self, target: impl Targetable) -> Self
pub fn with_target(self, target: impl Targetable) -> Self
specify the logger target
see Target for more details. note that this can be chained
with Logger::with_color_mode and Logger::with_formatter
use trillium_logger::{Logger, Target};
Logger::new().with_target(Target::Logger(log::Level::Info));Sourcepub fn without_init_message(self) -> Self
pub fn without_init_message(self) -> Self
Opt out of the init message
Sourcepub fn with_start_logging(self) -> Self
pub fn with_start_logging(self) -> Self
Also emit a log line when each request is received, before downstream handlers run
The start line is rendered by StartFormatter as Started {version} {method} {url}
unless replaced with Logger::with_start_formatter. The completion line is unaffected.
Start and completion lines from concurrent requests interleave; to pair them up, include a request identifier in both formatters.
use trillium_logger::Logger;
Logger::new().with_start_logging();Trait Implementations§
Source§impl<F, S> Handler for Logger<F, S>where
F: LogFormatter,
S: LogFormatter,
impl<F, S> Handler for Logger<F, S>where
F: LogFormatter,
S: LogFormatter,
Source§async fn init(&mut self, info: &mut Info)
async fn init(&mut self, info: &mut Info)
Source§async fn run(&self, conn: Conn) -> Conn
async fn run(&self, conn: Conn) -> Conn
Source§async fn before_send(&self, conn: Conn) -> Conn
async fn before_send(&self, conn: Conn) -> Conn
Source§fn has_upgrade(&self, upgrade: &Upgrade) -> bool
fn has_upgrade(&self, upgrade: &Upgrade) -> bool
Handler::upgrade. The first handler that responds true to this will receive
ownership of the trillium::Upgrade in a subsequent call to
Handler::upgradeSource§fn upgrade(&self, upgrade: Upgrade) -> impl Future<Output = ()> + Send
fn upgrade(&self, upgrade: Upgrade) -> impl Future<Output = ()> + Send
Handler::has_upgrade and will
only be called once for this upgrade. There is no return value, and this function takes
exclusive ownership of the underlying transport once this is called. You can downcast
the transport to whatever the source transport type is and perform any non-http protocol
communication that has been negotiated. You probably don’t want this unless you’re
implementing something like websockets. Please note that for many transports such as
TcpStreams, dropping the transport (and therefore the Upgrade) will hang up /
disconnect.