diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/config.rs | 5 | ||||
| -rw-r--r-- | src/main.rs | 16 |
2 files changed, 13 insertions, 8 deletions
diff --git a/src/config.rs b/src/config.rs index 271a340..df7a7ef 100644 --- a/src/config.rs +++ b/src/config.rs | |||
| @@ -500,6 +500,10 @@ pub struct Config { | |||
| 500 | /// Prevents connection exhaustion DoS attacks | 500 | /// Prevents connection exhaustion DoS attacks |
| 501 | #[arg(long, env = "NGIT_MAX_CONNECTIONS", default_value_t = 4096)] | 501 | #[arg(long, env = "NGIT_MAX_CONNECTIONS", default_value_t = 4096)] |
| 502 | pub max_connections: usize, | 502 | pub max_connections: usize, |
| 503 | |||
| 504 | /// Log level for application logging | ||
| 505 | #[arg(long, env = "NGIT_LOG_LEVEL", default_value = "info")] | ||
| 506 | pub log_level: String, | ||
| 503 | } | 507 | } |
| 504 | 508 | ||
| 505 | impl Config { | 509 | impl Config { |
| @@ -782,6 +786,7 @@ impl Config { | |||
| 782 | repository_blacklist: String::new(), | 786 | repository_blacklist: String::new(), |
| 783 | event_blacklist: String::new(), | 787 | event_blacklist: String::new(), |
| 784 | max_connections: 500, | 788 | max_connections: 500, |
| 789 | log_level: "debug".to_string(), | ||
| 785 | } | 790 | } |
| 786 | } | 791 | } |
| 787 | } | 792 | } |
diff --git a/src/main.rs b/src/main.rs index 5e5b83a..105b861 100644 --- a/src/main.rs +++ b/src/main.rs | |||
| @@ -3,8 +3,8 @@ use std::{path::PathBuf, sync::Arc}; | |||
| 3 | 3 | ||
| 4 | use anyhow::Result; | 4 | use anyhow::Result; |
| 5 | use tokio::signal; | 5 | use tokio::signal; |
| 6 | use tracing::{error, info, warn, Level}; | 6 | use tracing::{error, info, warn}; |
| 7 | use tracing_subscriber::FmtSubscriber; | 7 | use tracing_subscriber::{EnvFilter, FmtSubscriber}; |
| 8 | 8 | ||
| 9 | use ngit_grasp::{ | 9 | use ngit_grasp::{ |
| 10 | config::{Config, DatabaseBackend}, | 10 | config::{Config, DatabaseBackend}, |
| @@ -17,16 +17,16 @@ use ngit_grasp::{ | |||
| 17 | 17 | ||
| 18 | #[tokio::main] | 18 | #[tokio::main] |
| 19 | async fn main() -> Result<()> { | 19 | async fn main() -> Result<()> { |
| 20 | // Initialize tracing | 20 | // Load configuration first (priority: CLI flags > env vars > .env file > defaults) |
| 21 | let config = Config::load()?; | ||
| 22 | |||
| 23 | // Initialize tracing with configured log level | ||
| 21 | let subscriber = FmtSubscriber::builder() | 24 | let subscriber = FmtSubscriber::builder() |
| 22 | .with_max_level(Level::DEBUG) | 25 | .with_env_filter(EnvFilter::new(&config.log_level)) |
| 23 | .finish(); | 26 | .finish(); |
| 24 | tracing::subscriber::set_global_default(subscriber)?; | 27 | tracing::subscriber::set_global_default(subscriber)?; |
| 25 | 28 | ||
| 26 | info!("Starting ngit-grasp with nostr-relay-builder..."); | 29 | info!("Starting ngit-grasp with log level: {}", config.log_level); |
| 27 | |||
| 28 | // Load configuration (priority: CLI flags > env vars > .env file > defaults) | ||
| 29 | let config = Config::load()?; | ||
| 30 | 30 | ||
| 31 | // Validate configuration and fail fast on fatal errors | 31 | // Validate configuration and fail fast on fatal errors |
| 32 | // Recoverable issues (e.g., malformed whitelist entries) are logged as warnings | 32 | // Recoverable issues (e.g., malformed whitelist entries) are logged as warnings |