feat(backend): keep logs in daily rolling files

This commit is contained in:
2026-06-28 13:05:09 +03:00
parent eb95eed752
commit da9cd3e03b
4 changed files with 39 additions and 0 deletions

29
backend/Cargo.lock generated
View File

@@ -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"

View File

@@ -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"

View File

@@ -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();