From 544bfc21d513a5f8be272151634165763de3e1da Mon Sep 17 00:00:00 2001 From: Alexander Medvedev Date: Sun, 30 Aug 2026 11:59:45 +0200 Subject: [PATCH] chore: some more config options --- crates/pumpkin-config/src/logging.rs | 14 +++++++++++++- crates/pumpkin/src/lib.rs | 25 +++++++++++++++++++------ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/crates/pumpkin-config/src/logging.rs b/crates/pumpkin-config/src/logging.rs index 62c60eefd..1eae1f888 100644 --- a/crates/pumpkin-config/src/logging.rs +++ b/crates/pumpkin-config/src/logging.rs @@ -8,12 +8,20 @@ use serde::{Deserialize, Serialize}; pub struct LoggingConfig { /// Whether logging is enabled. pub enabled: bool, + /// Minimum log level for console and file output ("trace", "debug", "info", "warn", "error", "off"). + pub level: String, /// Whether to include thread names in log output. pub threads: bool, + /// Whether to include thread IDs in log output. + pub thread_ids: bool, + /// Whether to include target (module/component path) in log output. + pub target: bool, /// Whether to enable coloured log output. pub color: bool, /// Whether to include timestamps in log entries. pub timestamp: bool, + /// Format description for timestamps (using `time` format description syntax). + pub timestamp_format: String, /// Path to the log file. pub file: String, } @@ -22,9 +30,13 @@ impl Default for LoggingConfig { fn default() -> Self { Self { enabled: true, - threads: true, + level: "info".to_string(), + threads: false, + thread_ids: false, + target: false, color: true, timestamp: true, + timestamp_format: "[hour]:[minute]:[second]".to_string(), file: "latest.log".to_string(), } } diff --git a/crates/pumpkin/src/lib.rs b/crates/pumpkin/src/lib.rs index b607d7a3f..dfba67ed3 100644 --- a/crates/pumpkin/src/lib.rs +++ b/crates/pumpkin/src/lib.rs @@ -64,6 +64,8 @@ pub mod world; pub struct LoggingConfig { pub color: bool, pub threads: bool, + pub thread_ids: bool, + pub target: bool, pub timestamp: bool, } @@ -80,6 +82,7 @@ pub fn init_logger(advanced_config: &AdvancedConfiguration) { let level = std::env::var("RUST_LOG") .ok() .as_deref() + .or(Some(advanced_config.logging.level.as_str())) .map(LevelFilter::from_str) .and_then(Result::ok) .unwrap_or(LevelFilter::INFO); @@ -143,17 +146,25 @@ pub fn init_logger(advanced_config: &AdvancedConfiguration) { .with_writer(std::sync::Mutex::new(logger)) .with_ansi(advanced_config.logging.color) .with_ansi_sanitization(false) - .with_target(true) + .with_target(advanced_config.logging.target) .with_thread_names(advanced_config.logging.threads) - .with_thread_ids(advanced_config.logging.threads); + .with_thread_ids(advanced_config.logging.thread_ids); if advanced_config.logging.timestamp { let local_offset = time::UtcOffset::current_local_offset().unwrap_or(time::UtcOffset::UTC); - let fmt_layer = fmt_layer.with_timer(fmt::time::OffsetTime::new( - local_offset, - time::macros::format_description!("[year]-[month]-[day] [hour]:[minute]:[second]"), - )); + let format_str: &'static str = Box::leak( + advanced_config + .logging + .timestamp_format + .clone() + .into_boxed_str(), + ); + let timer_format = time::format_description::parse(format_str).unwrap_or_else(|_| { + time::macros::format_description!("[hour]:[minute]:[second]").to_vec() + }); + let fmt_layer = + fmt_layer.with_timer(fmt::time::OffsetTime::new(local_offset, timer_format)); let registry = tracing_subscriber::registry() .with(env_filter) .with(fmt_layer); @@ -177,6 +188,8 @@ pub fn init_logger(advanced_config: &AdvancedConfiguration) { let logging_config = LoggingConfig { color: advanced_config.logging.color, threads: advanced_config.logging.threads, + thread_ids: advanced_config.logging.thread_ids, + target: advanced_config.logging.target, timestamp: advanced_config.logging.timestamp, };