LoggerMiddleware
struct LoggerMiddleware
A middleware Logger that wraps an HTTP handler and logs request and response details.
Implementions
Methods
new
pub fn new(logger: Logger): LoggerMiddleware
[src]
pub fn new(logger: log.Logger): LoggerMiddleware {
return LoggerMiddleware { logger };
}
Creates a new Logger
middleware.
new
pub fn new(logger: Logger): LoggerMiddleware
[src]
pub fn new(logger: log.Logger): LoggerMiddleware {
return LoggerMiddleware { logger };
}
Creates a new Logger
middleware.
Creates a new Logger
middleware.
[src]
pub fn transform(self, handler: Handler): Handler {
return handler
.around(|handler, request| {
let remote_addr = request.remote_addr()?.to_string().unwrap_or("unknown");
self
.logger
.info(`Started method=${request.method()} path="${request.uri().path()}" remote_addr="${remote_addr}"`);
let start = Instant.now();
let resp = try handler.handle(request);
self.logger.info(`Completed ${resp.status()} in ${start.elapsed()}`);
return resp;
});
}
[src]
pub fn transform(self, handler: Handler): Handler {
return handler
.around(|handler, request| {
let remote_addr = request.remote_addr()?.to_string().unwrap_or("unknown");
self
.logger
.info(`Started method=${request.method()} path="${request.uri().path()}" remote_addr="${remote_addr}"`);
let start = Instant.now();
let resp = try handler.handle(request);
self.logger.info(`Completed ${resp.status()} in ${start.elapsed()}`);
return resp;
});
}