diff options
| -rw-r--r-- | .env.example | 7 | ||||
| -rw-r--r-- | docs/reference/configuration.md | 37 | ||||
| -rw-r--r-- | nix/module.nix | 11 | ||||
| -rw-r--r-- | src/config.rs | 5 | ||||
| -rw-r--r-- | src/main.rs | 16 |
5 files changed, 51 insertions, 25 deletions
diff --git a/.env.example b/.env.example index e152b89..01854f4 100644 --- a/.env.example +++ b/.env.example | |||
| @@ -101,9 +101,12 @@ | |||
| 101 | # LOGGING | 101 | # LOGGING |
| 102 | # ============================================================================ | 102 | # ============================================================================ |
| 103 | 103 | ||
| 104 | # Rust log level (not a ngit-grasp config, but useful for debugging) | 104 | # Log level for application logging |
| 105 | # CLI: --log-level <level> | ||
| 106 | # Default: info | ||
| 105 | # Options: error, warn, info, debug, trace | 107 | # Options: error, warn, info, debug, trace |
| 106 | # RUST_LOG=info | 108 | # Can also use filter expressions: ngit_grasp=debug,actix_web=info |
| 109 | # NGIT_LOG_LEVEL=info | ||
| 107 | 110 | ||
| 108 | # ============================================================================ | 111 | # ============================================================================ |
| 109 | # PROACTIVE SYNC (GRASP-02) | 112 | # PROACTIVE SYNC (GRASP-02) |
diff --git a/docs/reference/configuration.md b/docs/reference/configuration.md index b24b498..b09b20f 100644 --- a/docs/reference/configuration.md +++ b/docs/reference/configuration.md | |||
| @@ -1041,10 +1041,10 @@ Per-connection limits (built-in to relay-builder, not configurable): | |||
| 1041 | 1041 | ||
| 1042 | ### Logging Configuration | 1042 | ### Logging Configuration |
| 1043 | 1043 | ||
| 1044 | #### `RUST_LOG` | 1044 | #### `NGIT_LOG_LEVEL` |
| 1045 | 1045 | ||
| 1046 | **Description:** Logging level and filters (standard Rust environment variable) | 1046 | **Description:** Logging level and filters for application logging |
| 1047 | **Type:** String (log level or filter) | 1047 | **Type:** String (log level or filter expression) |
| 1048 | **Default:** `info` | 1048 | **Default:** `info` |
| 1049 | **Required:** No | 1049 | **Required:** No |
| 1050 | 1050 | ||
| @@ -1052,17 +1052,17 @@ Per-connection limits (built-in to relay-builder, not configurable): | |||
| 1052 | 1052 | ||
| 1053 | ```bash | 1053 | ```bash |
| 1054 | # Simple levels | 1054 | # Simple levels |
| 1055 | RUST_LOG=error # Errors only | 1055 | NGIT_LOG_LEVEL=error # Errors only |
| 1056 | RUST_LOG=warn # Warnings and errors | 1056 | NGIT_LOG_LEVEL=warn # Warnings and errors |
| 1057 | RUST_LOG=info # Info, warnings, errors | 1057 | NGIT_LOG_LEVEL=info # Info, warnings, errors (default) |
| 1058 | RUST_LOG=debug # Debug and above | 1058 | NGIT_LOG_LEVEL=debug # Debug and above |
| 1059 | RUST_LOG=trace # Everything | 1059 | NGIT_LOG_LEVEL=trace # Everything (very verbose) |
| 1060 | 1060 | ||
| 1061 | # Module-specific | 1061 | # Module-specific filtering |
| 1062 | RUST_LOG=ngit_grasp=debug,actix_web=info | 1062 | NGIT_LOG_LEVEL=ngit_grasp=debug,actix_web=info |
| 1063 | 1063 | ||
| 1064 | # Complex filters | 1064 | # Complex filters |
| 1065 | RUST_LOG=debug,hyper=info,tokio=warn | 1065 | NGIT_LOG_LEVEL=debug,hyper=info,tokio=warn |
| 1066 | ``` | 1066 | ``` |
| 1067 | 1067 | ||
| 1068 | **Log levels (most to least verbose):** | 1068 | **Log levels (most to least verbose):** |
| @@ -1073,12 +1073,25 @@ RUST_LOG=debug,hyper=info,tokio=warn | |||
| 1073 | 4. `warn` - Warnings about potential issues | 1073 | 4. `warn` - Warnings about potential issues |
| 1074 | 5. `error` - Errors only | 1074 | 5. `error` - Errors only |
| 1075 | 1075 | ||
| 1076 | **CLI flag:** | ||
| 1077 | |||
| 1078 | ```bash | ||
| 1079 | ngit-grasp --log-level trace | ||
| 1080 | ``` | ||
| 1081 | |||
| 1076 | **Production recommendation:** | 1082 | **Production recommendation:** |
| 1077 | 1083 | ||
| 1078 | ```bash | 1084 | ```bash |
| 1079 | RUST_LOG=info,ngit_grasp=debug | 1085 | NGIT_LOG_LEVEL=info |
| 1080 | ``` | 1086 | ``` |
| 1081 | 1087 | ||
| 1088 | **Notes:** | ||
| 1089 | |||
| 1090 | - Uses Rust's `tracing` crate filter syntax | ||
| 1091 | - Supports module-level filtering (e.g., `ngit_grasp=debug,hyper=info`) | ||
| 1092 | - `trace` level can significantly impact performance | ||
| 1093 | - For production, `info` or `warn` is recommended | ||
| 1094 | |||
| 1082 | --- | 1095 | --- |
| 1083 | 1096 | ||
| 1084 | ### Security Configuration (Planned) | 1097 | ### Security Configuration (Planned) |
diff --git a/nix/module.nix b/nix/module.nix index 4a6fc94..89d58de 100644 --- a/nix/module.nix +++ b/nix/module.nix | |||
| @@ -127,9 +127,14 @@ let | |||
| 127 | }; | 127 | }; |
| 128 | 128 | ||
| 129 | logLevel = mkOption { | 129 | logLevel = mkOption { |
| 130 | type = types.enum [ "trace" "debug" "info" "warn" "error" ]; | 130 | type = types.str; |
| 131 | default = "info"; | 131 | default = "info"; |
| 132 | description = "Logging level for RUST_LOG environment variable"; | 132 | example = "debug"; |
| 133 | description = '' | ||
| 134 | Logging level for application logging. | ||
| 135 | Can be a simple level (trace, debug, info, warn, error) or a filter expression. | ||
| 136 | Examples: "info", "debug", "ngit_grasp=debug,actix_web=info" | ||
| 137 | ''; | ||
| 133 | }; | 138 | }; |
| 134 | 139 | ||
| 135 | syncMaxBackoffSecs = mkOption { | 140 | syncMaxBackoffSecs = mkOption { |
| @@ -334,7 +339,7 @@ let | |||
| 334 | NGIT_REPOSITORY_BLACKLIST = concatStringsSep "," cfg.repositoryBlacklist; | 339 | NGIT_REPOSITORY_BLACKLIST = concatStringsSep "," cfg.repositoryBlacklist; |
| 335 | NGIT_EVENT_BLACKLIST = concatStringsSep "," cfg.eventBlacklist; | 340 | NGIT_EVENT_BLACKLIST = concatStringsSep "," cfg.eventBlacklist; |
| 336 | NGIT_MAX_CONNECTIONS = toString cfg.maxConnections; | 341 | NGIT_MAX_CONNECTIONS = toString cfg.maxConnections; |
| 337 | RUST_LOG = cfg.logLevel; | 342 | NGIT_LOG_LEVEL = cfg.logLevel; |
| 338 | } // optionalAttrs (cfg.relayName != null) { | 343 | } // optionalAttrs (cfg.relayName != null) { |
| 339 | NGIT_RELAY_NAME = cfg.relayName; | 344 | NGIT_RELAY_NAME = cfg.relayName; |
| 340 | } // optionalAttrs (cfg.archiveReadOnly != null) { | 345 | } // optionalAttrs (cfg.archiveReadOnly != null) { |
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 |