From 678dca6864b24d50303467b8b9945e5c2bba50ea Mon Sep 17 00:00:00 2001 From: Martin Bartlett Date: Mon, 16 Sep 2024 16:38:02 +0200 Subject: [PATCH 1/2] 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`. --- lambda-runtime-api-client/src/tracing.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lambda-runtime-api-client/src/tracing.rs b/lambda-runtime-api-client/src/tracing.rs index bdbdc3d8..2762efb1 100644 --- a/lambda-runtime-api-client/src/tracing.rs +++ b/lambda-runtime-api-client/src/tracing.rs @@ -33,14 +33,14 @@ const DEFAULT_LOG_LEVEL: &str = "INFO"; pub fn init_default_subscriber() { let log_format = env::var("AWS_LAMBDA_LOG_FORMAT").unwrap_or_default(); let log_level_str = env::var("AWS_LAMBDA_LOG_LEVEL").or_else(|_| env::var("RUST_LOG")); - let log_level = Level::from_str(log_level_str.as_deref().unwrap_or(DEFAULT_LOG_LEVEL)).unwrap_or(Level::INFO); + let log_level = LevelFilter::from_str(log_level_str.as_deref().unwrap_or(DEFAULT_LOG_LEVEL)).unwrap_or(LevelFilter::INFO); let collector = tracing_subscriber::fmt() .with_target(false) .without_time() .with_env_filter( EnvFilter::builder() - .with_default_directive(LevelFilter::from_level(log_level).into()) + .with_default_directive(log_level.into()) .from_env_lossy(), ); From 3db7693ecb0fc083ce1d9c8dcb815612752a17b6 Mon Sep 17 00:00:00 2001 From: Martin Bartlett Date: Mon, 16 Sep 2024 17:16:59 +0200 Subject: [PATCH 2/2] rustfmt --- lambda-runtime-api-client/src/tracing.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lambda-runtime-api-client/src/tracing.rs b/lambda-runtime-api-client/src/tracing.rs index 2762efb1..09f41991 100644 --- a/lambda-runtime-api-client/src/tracing.rs +++ b/lambda-runtime-api-client/src/tracing.rs @@ -33,7 +33,8 @@ const DEFAULT_LOG_LEVEL: &str = "INFO"; pub fn init_default_subscriber() { let log_format = env::var("AWS_LAMBDA_LOG_FORMAT").unwrap_or_default(); let log_level_str = env::var("AWS_LAMBDA_LOG_LEVEL").or_else(|_| env::var("RUST_LOG")); - let log_level = LevelFilter::from_str(log_level_str.as_deref().unwrap_or(DEFAULT_LOG_LEVEL)).unwrap_or(LevelFilter::INFO); + let log_level = + LevelFilter::from_str(log_level_str.as_deref().unwrap_or(DEFAULT_LOG_LEVEL)).unwrap_or(LevelFilter::INFO); let collector = tracing_subscriber::fmt() .with_target(false)