From da9cd3e03b01b377d335c83d3a7256ee510fd889 Mon Sep 17 00:00:00 2001 From: stefiosif Date: Sun, 28 Jun 2026 13:05:09 +0300 Subject: [PATCH] feat(backend): keep logs in daily rolling files --- .gitignore | 1 + backend/Cargo.lock | 29 +++++++++++++++++++++++++++++ backend/Cargo.toml | 1 + backend/src/main.rs | 8 ++++++++ 4 files changed, 39 insertions(+) diff --git a/.gitignore b/.gitignore index b88ba94..7ac0f49 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ node_modules/ docs/ +logs/ \ No newline at end of file diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 5fb5c86..e719743 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -307,6 +307,7 @@ dependencies = [ "tower-http", "tower_governor", "tracing", + "tracing-appender", "tracing-subscriber", "utoipa", "utoipa-swagger-ui", @@ -577,6 +578,15 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crossbeam-channel" +version = "0.5.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-deque" version = "0.8.6" @@ -3588,6 +3598,12 @@ version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" +[[package]] +name = "symlink" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7973cce6668464ea31f176d85b13c7ab3bba2cb3b77a2ed26abd7801688010a" + [[package]] name = "syn" version = "2.0.117" @@ -3900,6 +3916,19 @@ dependencies = [ "tracing-core", ] +[[package]] +name = "tracing-appender" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "050686193eb999b4bb3bc2acfa891a13da00f79734704c4b8b4ef1a10b368a3c" +dependencies = [ + "crossbeam-channel", + "symlink", + "thiserror 2.0.18", + "time", + "tracing-subscriber", +] + [[package]] name = "tracing-attributes" version = "0.1.31" diff --git a/backend/Cargo.toml b/backend/Cargo.toml index 37bfdc0..4497bf9 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -26,6 +26,7 @@ tower_governor = { version = "0.8.0", default-features = false, features = ["axu utoipa = { version = "5.5.0", features = ["axum_extras", "chrono"] } utoipa-swagger-ui = { version = "9.0.2", features = ["axum"] } image = "0.25.10" +tracing-appender = "0.2.5" [dev-dependencies] axum-test = "20.0.0" diff --git a/backend/src/main.rs b/backend/src/main.rs index f90ab9d..f7231ff 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -44,12 +44,20 @@ const BODY_LIMIT: usize = 1000 * 1000 * 1000 * 5; #[tokio::main] async fn main() -> Result<()> { + let file_appender = tracing_appender::rolling::daily("logs", "loft.log"); + let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender); + tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env().unwrap_or_else(|_| { format!("{}=info,tower_http=debug", env!("CARGO_CRATE_NAME")).into() }), ) + .with( + tracing_subscriber::fmt::layer() + .with_ansi(false) + .with_writer(non_blocking), + ) .with(tracing_subscriber::fmt::layer()) .init();