Skip to content

Commit 20206d7

Browse files
bassmanitramMartin Bartlett
and
Martin Bartlett
authored
Use event filter (#925)
* 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`. * rustfmt --------- Co-authored-by: Martin Bartlett <[email protected]>
1 parent 27191d0 commit 20206d7

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ 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 =
37+
LevelFilter::from_str(log_level_str.as_deref().unwrap_or(DEFAULT_LOG_LEVEL)).unwrap_or(LevelFilter::INFO);
3738

3839
let collector = tracing_subscriber::fmt()
3940
.with_target(false)
4041
.without_time()
4142
.with_env_filter(
4243
EnvFilter::builder()
43-
.with_default_directive(LevelFilter::from_level(log_level).into())
44+
.with_default_directive(log_level.into())
4445
.from_env_lossy(),
4546
);
4647

0 commit comments

Comments
 (0)