From aad28ef324b0e207bfd09a9c53b238d03054b382 Mon Sep 17 00:00:00 2001 From: Alexander Baranov Date: Thu, 7 May 2026 17:57:23 +0300 Subject: [PATCH] =?UTF-8?q?smart-house-web:=20=D0=B2=20=D1=80=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=82=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smart-house-web/backend/src/lib.rs | 16 ++++++++++++++++ smart-house-web/backend/src/main.rs | 8 ++------ 2 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 smart-house-web/backend/src/lib.rs diff --git a/smart-house-web/backend/src/lib.rs b/smart-house-web/backend/src/lib.rs new file mode 100644 index 0000000..fba8d83 --- /dev/null +++ b/smart-house-web/backend/src/lib.rs @@ -0,0 +1,16 @@ +pub fn init_logger() { + use tracing_subscriber::{Layer, layer::SubscriberExt, util::SubscriberInitExt}; + + let layer = tracing_subscriber::fmt::layer() + .with_thread_names(true) + .with_file(false) + .with_line_number(false) + .compact() + .boxed(); + if let Err(e) = tracing_subscriber::registry().with(vec![layer]).try_init() { + eprintln!("Logger initialization failed: {:?}", e); + std::process::exit(1); + } else { + tracing::trace!("Logger succesfully initialized"); + } +} diff --git a/smart-house-web/backend/src/main.rs b/smart-house-web/backend/src/main.rs index 395ac74..339cd95 100644 --- a/smart-house-web/backend/src/main.rs +++ b/smart-house-web/backend/src/main.rs @@ -1,10 +1,6 @@ -use tracing::info; +use backend::init_logger; fn main() { - // tracing_subscriber::fmt::init(); - let _s = tracing_subscriber::fmt() - .event_format(tracing_subscriber::fmt::format().compact()) - .init(); - info!("logger initialized"); + init_logger(); println!("Hello, world!"); }