2023-03-18 23:06:55 -04:00
|
|
|
use metrics_exporter_prometheus::PrometheusBuilder;
|
2024-10-21 11:42:32 +09:00
|
|
|
use tracing_subscriber::EnvFilter;
|
2023-02-15 19:27:36 -05:00
|
|
|
|
2024-06-16 21:56:14 +09:00
|
|
|
pub mod db;
|
|
|
|
|
pub mod proto;
|
2024-09-14 12:19:47 +09:00
|
|
|
pub mod util;
|
2024-06-16 21:56:14 +09:00
|
|
|
|
|
|
|
|
pub mod _config;
|
2023-02-15 19:27:36 -05:00
|
|
|
pub use crate::_config::CONFIG as config;
|
|
|
|
|
|
|
|
|
|
pub fn init_logging(component: &str) -> anyhow::Result<()> {
|
2024-09-14 12:19:47 +09:00
|
|
|
// todo: fix component
|
|
|
|
|
if config.json_log {
|
|
|
|
|
tracing_subscriber::fmt()
|
|
|
|
|
.json()
|
|
|
|
|
.with_env_filter(EnvFilter::from_default_env())
|
|
|
|
|
.init();
|
2023-02-15 19:27:36 -05:00
|
|
|
} else {
|
2024-09-14 12:19:47 +09:00
|
|
|
tracing_subscriber::fmt()
|
|
|
|
|
.with_env_filter(EnvFilter::from_default_env())
|
|
|
|
|
.init();
|
2023-02-15 19:27:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
2023-03-18 23:06:55 -04:00
|
|
|
|
|
|
|
|
pub fn init_metrics() -> anyhow::Result<()> {
|
|
|
|
|
if config.run_metrics_server {
|
|
|
|
|
// automatically spawns a http listener at :9000
|
|
|
|
|
let builder = PrometheusBuilder::new();
|
|
|
|
|
builder.install()?;
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|