From 1ae97cd85aec95f6270f853b28e48774cefc6bf6 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Mon, 26 Jan 2026 16:17:55 +0000 Subject: feat: add NGIT_LOG_LEVEL configuration option Add proper log level configuration following standard approach: - CLI flag: --log-level - Environment variable: NGIT_LOG_LEVEL - Default: info - Supports simple levels (error, warn, info, debug, trace) - Supports filter expressions (e.g., ngit_grasp=debug,actix_web=info) Configuration is now consistent across all four sources: 1. src/config.rs - Config struct with log_level field 2. docs/reference/configuration.md - Full documentation 3. nix/module.nix - NixOS module with logLevel option 4. .env.example - Example configuration file This replaces the previous RUST_LOG approach with proper integration into the ngit-grasp configuration system, enabling trace logging from CLI, environment variables, or NixOS configuration. --- src/config.rs | 5 +++++ src/main.rs | 16 ++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) (limited to 'src') 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 { /// Prevents connection exhaustion DoS attacks #[arg(long, env = "NGIT_MAX_CONNECTIONS", default_value_t = 4096)] pub max_connections: usize, + + /// Log level for application logging + #[arg(long, env = "NGIT_LOG_LEVEL", default_value = "info")] + pub log_level: String, } impl Config { @@ -782,6 +786,7 @@ impl Config { repository_blacklist: String::new(), event_blacklist: String::new(), max_connections: 500, + log_level: "debug".to_string(), } } } 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}; use anyhow::Result; use tokio::signal; -use tracing::{error, info, warn, Level}; -use tracing_subscriber::FmtSubscriber; +use tracing::{error, info, warn}; +use tracing_subscriber::{EnvFilter, FmtSubscriber}; use ngit_grasp::{ config::{Config, DatabaseBackend}, @@ -17,16 +17,16 @@ use ngit_grasp::{ #[tokio::main] async fn main() -> Result<()> { - // Initialize tracing + // Load configuration first (priority: CLI flags > env vars > .env file > defaults) + let config = Config::load()?; + + // Initialize tracing with configured log level let subscriber = FmtSubscriber::builder() - .with_max_level(Level::DEBUG) + .with_env_filter(EnvFilter::new(&config.log_level)) .finish(); tracing::subscriber::set_global_default(subscriber)?; - info!("Starting ngit-grasp with nostr-relay-builder..."); - - // Load configuration (priority: CLI flags > env vars > .env file > defaults) - let config = Config::load()?; + info!("Starting ngit-grasp with log level: {}", config.log_level); // Validate configuration and fail fast on fatal errors // Recoverable issues (e.g., malformed whitelist entries) are logged as warnings -- cgit v1.2.3