diff --git a/crates/store_sqlite/src/lib.rs b/crates/store_sqlite/src/lib.rs index 7bc6126..1f8d8ce 100644 --- a/crates/store_sqlite/src/lib.rs +++ b/crates/store_sqlite/src/lib.rs @@ -1,14 +1,13 @@ +pub use error::Error; use serde::Serialize; use sqlx::{Pool, Sqlite, SqlitePool, sqlite::SqliteConnectOptions}; - +use tracing::info; pub mod addressbook_store; pub mod calendar_store; pub mod error; pub mod principal_store; pub mod subscription_store; -pub use error::Error; - #[derive(Debug, Clone, Serialize, sqlx::Type)] #[serde(rename_all = "kebab-case")] pub(crate) enum ChangeOperation { @@ -38,7 +37,7 @@ pub async fn create_db_pool(db_url: &str, migrate: bool) -> Result, ) .await?; if migrate { - println!("Running database migrations"); + info!("Running database migrations"); sqlx::migrate!("./migrations").run(&db).await?; } Ok(db) diff --git a/src/app.rs b/src/app.rs index 29a3bf0..1dffe9a 100644 --- a/src/app.rs +++ b/src/app.rs @@ -1,6 +1,7 @@ use axum::Router; use axum::extract::Request; use axum::response::Response; +use reqwest::StatusCode; use rustical_caldav::caldav_router; use rustical_carddav::carddav_router; use rustical_frontend::nextcloud_login::{NextcloudFlows, nextcloud_login_router}; @@ -16,6 +17,7 @@ use tower_http::trace::TraceLayer; use tower_sessions::cookie::SameSite; use tower_sessions::{Expiry, MemoryStore, SessionManagerLayer}; use tracing::Span; +use tracing::field::display; use crate::config::NextcloudLoginConfig; @@ -76,7 +78,7 @@ pub fn make_app( .layer( TraceLayer::new_for_http() .make_span_with(|request: &Request| { - tracing::debug_span!( + tracing::info_span!( "http-request", status_code = tracing::field::Empty, otel.name = tracing::field::display(format!( @@ -86,13 +88,22 @@ pub fn make_app( )), ) }) - .on_request(|_req: &Request, _span: &Span| {}) + .on_request(|req: &Request, span: &Span| { + span.record("method", display(req.method())); + span.record("path", display(req.uri())); + }) .on_response(|response: &Response, _latency: Duration, span: &Span| { - span.record("status_code", tracing::field::display(response.status())); + span.record("status_code", display(response.status())); if response.status().is_server_error() { - tracing::error!("status server error"); + tracing::error!("server error"); } else if response.status().is_client_error() { - tracing::error!("status client error"); + if response.status() == StatusCode::UNAUTHORIZED { + // The iOS client always tries an unauthenticated request first so + // logging 401's as errors would clog up our logs + tracing::debug!("unauthorized"); + } else { + tracing::error!("client error"); + } }; }) .on_failure( diff --git a/src/main.rs b/src/main.rs index ca1bfbb..1d20350 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,6 +22,7 @@ use std::sync::Arc; use tokio::sync::mpsc::Receiver; use tower::Layer; use tower_http::normalize_path::NormalizePathLayer; +use tracing::info; mod app; mod commands; @@ -125,12 +126,10 @@ async fn main() -> Result<()> { NormalizePathLayer::trim_trailing_slash().layer(app), ); - let listener = tokio::net::TcpListener::bind(&format!( - "{}:{}", - config.http.host, config.http.port - )) - .await?; - tasks.push(tokio::spawn(async { + let address = format!("{}:{}", config.http.host, config.http.port); + let listener = tokio::net::TcpListener::bind(&address).await?; + tasks.push(tokio::spawn(async move { + info!("RustiCal serving on http://{address}"); axum::serve(listener, app).await.unwrap() }));