From 0fbc730818519cac233942df7182937dad1d7973 Mon Sep 17 00:00:00 2001 From: Noah Date: Fri, 3 Jan 2025 06:35:28 -0500 Subject: [PATCH] fix listening to `RUST_LOG` (#448) Per the logger documentation: > Enables the user to choose log level by setting RUST_LOG= environment variable. This will use the default level set by with_level if RUST_LOG is not set or can't be parsed as a standard log level. > This must be called after with_level. If called before with_level, it will have no effect. Personally, I feel that using a config file, which defaults to *false* to configure whether or not to listen to the environment for enabling and disabling logging is a bit dumb. Usually environment variables are meant to allow you to modify the configuration of a program for one "environment", not necessarily permanently. Especially when you get more complicated environment filtering. Additionally, I'd like to use this as a springboard to advocate for a few things, primarily introducing the idea of migrating away from `log` to `tracing`, as there's a lot more that can be done with regards to performance testing. --- pumpkin/src/main.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pumpkin/src/main.rs b/pumpkin/src/main.rs index 5a2ec8f4..fb18b177 100644 --- a/pumpkin/src/main.rs +++ b/pumpkin/src/main.rs @@ -85,14 +85,15 @@ fn init_logger() { logger = logger.without_timestamps(); } - if ADVANCED_CONFIG.logging.env { - logger = logger.env(); - } - logger = logger.with_level(convert_logger_filter(ADVANCED_CONFIG.logging.level)); logger = logger.with_colors(ADVANCED_CONFIG.logging.color); logger = logger.with_threads(ADVANCED_CONFIG.logging.threads); + + if ADVANCED_CONFIG.logging.env { + logger = logger.env(); + } + logger.init().unwrap(); } }