refactor: include binary name in service field in log entries (#2077)

This commit is contained in:
Sanchith Hegde
2023-09-04 17:14:47 +05:30
committed by GitHub
parent e1cebd4179
commit 20d44acd20
10 changed files with 43 additions and 54 deletions

View File

@ -34,7 +34,11 @@ async fn main() -> ApplicationResult<()> {
conf.validate()
.expect("Failed to validate router configuration");
let _guard = logger::setup(&conf.log, [router_env::service_name!(), "actix_server"]);
let _guard = router_env::setup(
&conf.log,
router_env::service_name!(),
[router_env::service_name!(), "actix_server"],
);
logger::info!("Application started [{:?}] [{:?}]", conf.server, conf.log);

View File

@ -1,5 +1,5 @@
#![recursion_limit = "256"]
use std::sync::Arc;
use std::{str::FromStr, sync::Arc};
use error_stack::ResultExt;
use router::{
@ -37,11 +37,23 @@ async fn main() -> CustomResult<(), errors::ProcessTrackerError> {
redis_shutdown_signal_rx,
tx.clone(),
));
let _guard = logger::setup(&state.conf.log, [router_env::service_name!()]);
#[allow(clippy::expect_used)]
let scheduler_flow_str =
std::env::var(SCHEDULER_FLOW).expect("SCHEDULER_FLOW environment variable not set");
#[allow(clippy::expect_used)]
let scheduler_flow = scheduler::SchedulerFlow::from_str(&scheduler_flow_str)
.expect("Unable to parse SchedulerFlow from environment variable");
let _guard = router_env::setup(
&state.conf.log,
&scheduler_flow_str,
[router_env::service_name!()],
);
logger::debug!(startup_config=?state.conf);
start_scheduler(&state, (tx, rx)).await?;
start_scheduler(&state, scheduler_flow, (tx, rx)).await?;
eprintln!("Scheduler shut down");
Ok(())
@ -49,20 +61,14 @@ async fn main() -> CustomResult<(), errors::ProcessTrackerError> {
async fn start_scheduler(
state: &routes::AppState,
scheduler_flow: scheduler::SchedulerFlow,
channel: (mpsc::Sender<()>, mpsc::Receiver<()>),
) -> CustomResult<(), errors::ProcessTrackerError> {
use std::str::FromStr;
#[allow(clippy::expect_used)]
let flow = std::env::var(SCHEDULER_FLOW).expect("SCHEDULER_FLOW environment variable not set");
#[allow(clippy::expect_used)]
let flow = scheduler::SchedulerFlow::from_str(&flow)
.expect("Unable to parse SchedulerFlow from environment variable");
let scheduler_settings = state
.conf
.scheduler
.clone()
.ok_or(errors::ProcessTrackerError::ConfigurationError)?;
scheduler::start_process_tracker(state, flow, Arc::new(scheduler_settings), channel).await
scheduler::start_process_tracker(state, scheduler_flow, Arc::new(scheduler_settings), channel)
.await
}

View File

@ -1,14 +1,2 @@
#[doc(inline)]
pub use router_env::*;
pub mod logger {
#[doc(inline)]
pub use router_env::{log, logger::*};
/// Setup logging sub-system.
pub fn setup(
conf: &config::Log,
crates_to_filter: impl AsRef<[&'static str]>,
) -> TelemetryGuard {
router_env::setup(conf, router_env::service_name!(), crates_to_filter)
}
}