Skip to content

Commit

Permalink
fix listening to RUST_LOG (#448)
Browse files Browse the repository at this point in the history
Per the logger documentation:

> Enables the user to choose log level by setting RUST_LOG=<level> 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.
  • Loading branch information
StripedMonkey authored Jan 3, 2025
1 parent 2a935d0 commit 0fbc730
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pumpkin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down

0 comments on commit 0fbc730

Please sign in to comment.