From 4d12dfd7e0706872bc352de60975317f5d3046a0 Mon Sep 17 00:00:00 2001 From: Zynh0722 Date: Thu, 13 Apr 2023 11:49:13 -0700 Subject: [PATCH] logging ig --- src/main.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index 82a40eb..e7f66e2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,9 +2,10 @@ use async_zip::tokio::write::ZipFileWriter; use async_zip::{Compression, ZipEntryBuilder}; use axum::body::StreamBody; -use axum::extract::State; -use axum::http::StatusCode; -use axum::response::IntoResponse; +use axum::extract::{ConnectInfo, State}; +use axum::http::{Request, StatusCode}; +use axum::middleware::{Next, self}; +use axum::response::{IntoResponse, Response}; use axum::routing::{get, post}; use axum::{ extract::{DefaultBodyLimit, Multipart}, @@ -74,19 +75,26 @@ async fn main() -> io::Result<()> { )) .with_state(state) .nest_service("/", ServeDir::new("dist")) - .layer(TraceLayer::new_for_http()); + .layer(TraceLayer::new_for_http()) + .layer(middleware::from_fn(log_source)); // Server creation let addr = SocketAddr::from(([0, 0, 0, 0], 3000)); tracing::debug!("listening on http://{}/", addr); axum::Server::bind(&addr) - .serve(app.into_make_service()) + .serve(app.into_make_service_with_connect_info::()) .await .unwrap(); Ok(()) } +async fn log_source(ConnectInfo(addr): ConnectInfo, req: Request, next: Next) -> Response { + tracing::info!("{}", addr); + + next.run(req).await +} + async fn upload_to_zip( State(state): State, mut body: Multipart,