Files
rust-otus/smart-house-web/backend/src/lib.rs

38 lines
1.1 KiB
Rust

const CODE_LOGGER_INITIALIZATION_ERROR: i32 = 1;
const CODE_TOKIO_RUNTIME_CREATION_ERROR: i32 = 2;
const CODE_LISTENER_BINDING_ERROR: i32 = 3;
const CODE_STARTIG_SERVER_ERROR: i32 = 4;
const CODE_CTRL_C_SIGNAL_INSTALL_ERROR: i32 = 5;
pub fn init_logger() {
use std::process::exit;
use tracing::{Level, trace};
use tracing_subscriber::{
Layer, filter::Targets, fmt::layer, layer::SubscriberExt, registry, util::SubscriberInitExt,
};
let layer = layer()
.compact()
.with_thread_names(true)
.with_file(false)
.with_line_number(false)
.with_filter(
Targets::new()
.with_target("axum::serve", Level::INFO)
.with_default(Level::TRACE),
)
.boxed();
if let Err(e) = registry().with(vec![layer]).try_init() {
eprintln!("Logger initialization failed: {:?}", e);
exit(CODE_LOGGER_INITIALIZATION_ERROR);
} else {
trace!("Logger succesfully initialized");
}
}
mod server;
pub use server::run_server;
mod house;
pub use house::{Device, PowerSocket, Thermometer};