pub struct RequestLoggerLayer { /* private fields */ }Expand description
Tower layer for the request logging middleware.
This is the main entry point for using the outlet middleware. It implements the Tower
Layer trait and can be used with Axum’s layering system.
The layer spawns a background task to process captured request/response data using
the provided RequestHandler.
§Examples
use outlet::{RequestLoggerLayer, RequestLoggerConfig, LoggingHandler};
use axum::{routing::get, Router};
use tower::ServiceBuilder;
let config = RequestLoggerConfig::default();
let handler = LoggingHandler;
let layer = RequestLoggerLayer::new(config, handler);
let app = Router::new()
.route("/hello", get(hello))
.layer(ServiceBuilder::new().layer(layer));
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();Implementations§
Source§impl RequestLoggerLayer
impl RequestLoggerLayer
Sourcepub fn new<H: RequestHandler>(config: RequestLoggerConfig, handler: H) -> Self
pub fn new<H: RequestHandler>(config: RequestLoggerConfig, handler: H) -> Self
Create a new request logger layer with the given configuration and handler.
This spawns a background task that will process captured request/response data using the provided handler.
§Arguments
config- Configuration controlling what data to capturehandler- Implementation ofRequestHandlerto process the captured data
§Examples
use outlet::{RequestLoggerLayer, RequestLoggerConfig, LoggingHandler};
let config = RequestLoggerConfig {
capture_request_body: true,
capture_response_body: true,
};
let handler = LoggingHandler;
// Spawns the background task that runs the provided handler
let layer = RequestLoggerLayer::new(config, handler);
// use the layer anywhere you'd use a tower layer, and your handler will be called (in the
// background) as each request traverses the layer.Trait Implementations§
Source§impl Clone for RequestLoggerLayer
impl Clone for RequestLoggerLayer
Source§fn clone(&self) -> RequestLoggerLayer
fn clone(&self) -> RequestLoggerLayer
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for RequestLoggerLayer
impl RefUnwindSafe for RequestLoggerLayer
impl Send for RequestLoggerLayer
impl Sync for RequestLoggerLayer
impl Unpin for RequestLoggerLayer
impl UnwindSafe for RequestLoggerLayer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more