[refactor] abstracted logging initialization and app settings loading into dedicated functions to streamline main.rs
and improve code readability
This commit is contained in:
@@ -15,23 +15,11 @@ use tracing_subscriber::EnvFilter;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
tracing_subscriber::fmt()
|
||||
.with_target(false)
|
||||
.compact()
|
||||
.with_env_filter(EnvFilter::from_default_env())
|
||||
.json() // For Production
|
||||
.init();
|
||||
init_logging();
|
||||
|
||||
info!("Starting server");
|
||||
|
||||
AppSettings::default();
|
||||
let mut app_settings = AppSettings::get_app_settings();
|
||||
|
||||
AppSettings::ensure_default_directory(&app_settings)
|
||||
.expect("Failed to create default directory");
|
||||
|
||||
app_settings.config = ConfigFile::load_from_file(&AppSettings::get_app_settings())
|
||||
.expect("Failed to load config file");
|
||||
let app_settings = load_app_settings();
|
||||
|
||||
let pool = db::initialize_db(&app_settings).await?;
|
||||
let app = create_app(pool);
|
||||
@@ -65,6 +53,32 @@ async fn health_check() -> &'static str {
|
||||
"OK"
|
||||
}
|
||||
|
||||
fn init_logging() {
|
||||
tracing_subscriber::fmt()
|
||||
.with_target(false)
|
||||
.compact()
|
||||
// .with_env_filter(EnvFilter::from_default_env())
|
||||
// .json() // For Production
|
||||
.init();
|
||||
}
|
||||
|
||||
fn load_app_settings() -> AppSettings {
|
||||
AppSettings::default();
|
||||
let app_settings = AppSettings::get_app_settings();
|
||||
|
||||
AppSettings::ensure_default_directory(&app_settings)
|
||||
.expect("Failed to create default directory");
|
||||
|
||||
let config = ConfigFile::load_from_file(&AppSettings::get_app_settings())
|
||||
.expect("Failed to load config file");
|
||||
|
||||
let app_settings = AppSettings {
|
||||
config,
|
||||
..app_settings
|
||||
};
|
||||
app_settings
|
||||
}
|
||||
|
||||
async fn shutdown_signal() {
|
||||
let ctrl_c = async {
|
||||
signal::ctrl_c()
|
||||
|
Reference in New Issue
Block a user