mz_frontegg_mock/middleware/
logging.rs

1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10use axum::{extract::Request, middleware::Next, response::Response};
11use mz_ore::instrument;
12use std::time::Instant;
13
14#[instrument]
15pub async fn logging_middleware(request: Request, next: Next) -> Response {
16    let start: Instant = Instant::now();
17    let method: hyper::Method = request.method().clone();
18    let uri = request.uri().clone();
19
20    let response = next.run(request).await;
21
22    let latency = start.elapsed();
23    let status = response.status();
24
25    tracing::info!(
26        method = %method,
27        uri = %uri,
28        status = %status,
29        latency = ?latency,
30        "Request completed"
31    );
32
33    response
34}