Skip to content

Commit 678dca6

Browse files
author
Martin Bartlett
committed
Use LevelFilter instead of Level
Originally a `Level` was parsed from one of two environment variables (or defaulted) and then converted into a `LevelFilter` before initializing the subscriber. However, this precludes using `RUST_LOG=off` since `Level` does not recognize that as valid, resulting in `Level::INFO` (the default) being used. `LevelFilter` (to which the above is converted anyway) _does_ allow the value to be `off` - so it seems a little more flexible (and very very minutely faster) to parse the env var or default value directly into a `LevelFilter`.
1 parent 27191d0 commit 678dca6

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lambda-runtime-api-client/src/tracing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ const DEFAULT_LOG_LEVEL: &str = "INFO";
3333
pub fn init_default_subscriber() {
3434
let log_format = env::var("AWS_LAMBDA_LOG_FORMAT").unwrap_or_default();
3535
let log_level_str = env::var("AWS_LAMBDA_LOG_LEVEL").or_else(|_| env::var("RUST_LOG"));
36-
let log_level = Level::from_str(log_level_str.as_deref().unwrap_or(DEFAULT_LOG_LEVEL)).unwrap_or(Level::INFO);
36+
let log_level = LevelFilter::from_str(log_level_str.as_deref().unwrap_or(DEFAULT_LOG_LEVEL)).unwrap_or(LevelFilter::INFO);
3737

3838
let collector = tracing_subscriber::fmt()
3939
.with_target(false)
4040
.without_time()
4141
.with_env_filter(
4242
EnvFilter::builder()
43-
.with_default_directive(LevelFilter::from_level(log_level).into())
43+
.with_default_directive(log_level.into())
4444
.from_env_lossy(),
4545
);
4646

0 commit comments

Comments
 (0)