From cc77a5cdb2d2e2858c2ea902b922f64a729f30f5 Mon Sep 17 00:00:00 2001 From: requesco Date: Thu, 4 Jan 2024 13:25:09 +0200 Subject: [PATCH] comments --- nft_ingester/src/bin/ingester/main.rs | 3 ++- nft_ingester/src/config.rs | 14 ++++++++++---- postgre-client/src/lib.rs | 11 +++++++---- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/nft_ingester/src/bin/ingester/main.rs b/nft_ingester/src/bin/ingester/main.rs index 84498338f..530ddbe44 100644 --- a/nft_ingester/src/bin/ingester/main.rs +++ b/nft_ingester/src/bin/ingester/main.rs @@ -49,8 +49,8 @@ pub async fn main() -> Result<(), IngesterError> { info!("Starting Ingester"); let args = Args::parse(); - init_logger(); let config: IngesterConfig = setup_config(); + init_logger(&config.get_log_level()); let bg_tasks_config = config .clone() .background_task_runner_config @@ -297,6 +297,7 @@ pub async fn main() -> Result<(), IngesterError> { let index_storage = Arc::new( PgClient::new( &config.database_config.get_database_url().unwrap(), + &config.get_log_level(), 100, max_postgre_connections, ) diff --git a/nft_ingester/src/config.rs b/nft_ingester/src/config.rs index 9736b6440..53b755e3e 100644 --- a/nft_ingester/src/config.rs +++ b/nft_ingester/src/config.rs @@ -91,6 +91,7 @@ pub struct IngesterConfig { pub gapfiller_peer_addr: String, pub peer_grpc_port: u16, pub peer_grpc_max_gap_slots: u64, + pub rust_log: Option, } impl IngesterConfig { @@ -122,6 +123,10 @@ impl IngesterConfig { pub fn get_is_snapshot(&self) -> bool { self.is_snapshot.unwrap_or_default() } + + pub fn get_log_level(&self) -> String { + self.rust_log.clone().unwrap_or("warn".to_string()) + } } // Types and constants used for Figment configuration items. @@ -364,7 +369,9 @@ impl PeerDiscovery for IngesterConfig { } pub fn setup_config<'a, T: Deserialize<'a>>() -> T { - let figment = Figment::new().join(Env::prefixed("INGESTER_")); + let figment = Figment::new() + .join(Env::prefixed("INGESTER_")) + .join(Env::raw()); figment .extract() @@ -374,8 +381,7 @@ pub fn setup_config<'a, T: Deserialize<'a>>() -> T { .unwrap() } -pub fn init_logger() { - let env_filter = env::var("RUST_LOG").unwrap_or("info".to_string()); - let t = tracing_subscriber::fmt().with_env_filter(env_filter); +pub fn init_logger(log_level: &str) { + let t = tracing_subscriber::fmt().with_env_filter(log_level); t.event_format(fmt::format::json()).init(); } diff --git a/postgre-client/src/lib.rs b/postgre-client/src/lib.rs index 77c586cb3..ff77ec3b2 100644 --- a/postgre-client/src/lib.rs +++ b/postgre-client/src/lib.rs @@ -3,7 +3,6 @@ use sqlx::{ ConnectOptions, PgPool, Postgres, QueryBuilder, Row, Transaction, }; use std::collections::HashMap; -use std::env; use std::str::FromStr; use tracing::log::LevelFilter; @@ -18,10 +17,14 @@ pub struct PgClient { } impl PgClient { - pub async fn new(url: &str, min_connections: u32, max_connections: u32) -> Self { + pub async fn new( + url: &str, + log_level: &str, + min_connections: u32, + max_connections: u32, + ) -> Self { let mut options: PgConnectOptions = url.parse().unwrap(); - let log_statements = env::var("RUST_LOG").unwrap_or_else(|_| "warn".to_string()); - options.log_statements(LevelFilter::from_str(&log_statements).unwrap_or(LevelFilter::Warn)); + options.log_statements(LevelFilter::from_str(log_level).unwrap_or(LevelFilter::Warn)); let pool = PgPoolOptions::new() .min_connections(min_connections)