tracing improvements
This commit is contained in:
parent
6551b0ed90
commit
f9eec3be3a
4 changed files with 38 additions and 3 deletions
18
Cargo.lock
generated
18
Cargo.lock
generated
|
@ -2866,6 +2866,22 @@ dependencies = [
|
|||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tower-http"
|
||||
version = "0.6.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "adc82fd73de2a9722ac5da747f12383d2bfdb93591ee6c58486e0097890f05f2"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"bytes",
|
||||
"http",
|
||||
"http-body",
|
||||
"pin-project-lite",
|
||||
"tower-layer",
|
||||
"tower-service",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tower-layer"
|
||||
version = "0.3.3"
|
||||
|
@ -3583,6 +3599,8 @@ dependencies = [
|
|||
"tokio",
|
||||
"tokio-stream",
|
||||
"tokio-util",
|
||||
"tower",
|
||||
"tower-http",
|
||||
"tracing",
|
||||
"tracing-subscriber",
|
||||
"uuid",
|
||||
|
|
|
@ -23,8 +23,10 @@ thiserror = "2.0"
|
|||
tokio = { version = "1.28.2", features = ["full"] }
|
||||
tokio-stream = "0.1"
|
||||
tokio-util = "0.7.15"
|
||||
tower = "0.5.2"
|
||||
tower-http = { version = "0.6.6", features = ["trace"] }
|
||||
tracing = "0.1.37"
|
||||
tracing-subscriber = { version = "0.3", features =["env-filter"] }
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter", "fmt"] }
|
||||
uuid = { version = "1.16.0", features = ["v4"] }
|
||||
|
||||
[dev-dependencies]
|
||||
|
|
|
@ -12,6 +12,7 @@ use std::pin::pin;
|
|||
use std::pin::Pin;
|
||||
use std::sync::Arc;
|
||||
use tokio::signal;
|
||||
use tower_http::trace::TraceLayer;
|
||||
use tracing::info;
|
||||
|
||||
use crate::Conf;
|
||||
|
@ -52,7 +53,9 @@ impl ZeroToAxum {
|
|||
db,
|
||||
};
|
||||
|
||||
let app = routes::build().with_state(app_state);
|
||||
let app = routes::build()
|
||||
.with_state(app_state)
|
||||
.layer(TraceLayer::new_for_http());
|
||||
|
||||
let listener = tokio::net::TcpListener::bind(&conf.listen).await.unwrap();
|
||||
let bound_addr = listener.local_addr().unwrap();
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use std::fmt;
|
||||
|
||||
use axum::{http::StatusCode, response::IntoResponse, routing::post, Form, Router};
|
||||
use axum_extra::extract::cookie::{Cookie, PrivateCookieJar};
|
||||
use serde::Deserialize;
|
||||
|
@ -17,11 +19,21 @@ pub struct LoginForm {
|
|||
password: String,
|
||||
}
|
||||
|
||||
impl fmt::Debug for LoginForm {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.debug_struct("LoginForm")
|
||||
.field("username", &self.username)
|
||||
.field("password", &"REDACTED")
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument]
|
||||
pub async fn login(
|
||||
jar: PrivateCookieJar,
|
||||
Form(form): Form<LoginForm>,
|
||||
) -> Result<PrivateCookieJar, LoginError> {
|
||||
info!(form.username, form.password, "login attempt");
|
||||
info!("login attempt");
|
||||
|
||||
if form.username != "admin" {
|
||||
return Err(LoginError::UnknownUser);
|
||||
|
|
Loading…
Add table
Reference in a new issue