Skip to content

Commit 5a03654

Browse files
authored
tracing: fix perf regression when release_max_level_* not set (#3373)
## Motivation This PR fixes perf regression (binary size and instruction counts) existed in tracing > 0.1.37 in case if `release_max_level_*` feature was not set, but `max_level_*` was. ## Solution Regression was introduced in #2553, where logic was unintentionally changed: before pr, in case if `release_max_level_*` wasn't set, log level from `max_level_*` was used, but after it was unconditionally set to trace level. See additional info in #2553 (comment)
1 parent ed3300c commit 5a03654

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

tracing/src/level_filters.rs

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,36 @@ pub use tracing_core::{metadata::ParseLevelFilterError, LevelFilter};
6666
pub const STATIC_MAX_LEVEL: LevelFilter = get_max_level_inner();
6767

6868
const fn get_max_level_inner() -> LevelFilter {
69-
if cfg!(not(debug_assertions)) {
70-
if cfg!(feature = "release_max_level_off") {
71-
LevelFilter::OFF
72-
} else if cfg!(feature = "release_max_level_error") {
73-
LevelFilter::ERROR
74-
} else if cfg!(feature = "release_max_level_warn") {
75-
LevelFilter::WARN
76-
} else if cfg!(feature = "release_max_level_info") {
77-
LevelFilter::INFO
78-
} else if cfg!(feature = "release_max_level_debug") {
79-
LevelFilter::DEBUG
80-
} else {
81-
// Same as branch cfg!(feature = "release_max_level_trace")
82-
LevelFilter::TRACE
83-
}
69+
if cfg!(all(
70+
not(debug_assertions),
71+
feature = "release_max_level_off"
72+
)) {
73+
LevelFilter::OFF
74+
} else if cfg!(all(
75+
not(debug_assertions),
76+
feature = "release_max_level_error"
77+
)) {
78+
LevelFilter::ERROR
79+
} else if cfg!(all(
80+
not(debug_assertions),
81+
feature = "release_max_level_warn"
82+
)) {
83+
LevelFilter::WARN
84+
} else if cfg!(all(
85+
not(debug_assertions),
86+
feature = "release_max_level_info"
87+
)) {
88+
LevelFilter::INFO
89+
} else if cfg!(all(
90+
not(debug_assertions),
91+
feature = "release_max_level_debug"
92+
)) {
93+
LevelFilter::DEBUG
94+
} else if cfg!(all(
95+
not(debug_assertions),
96+
feature = "release_max_level_trace"
97+
)) {
98+
LevelFilter::TRACE
8499
} else if cfg!(feature = "max_level_off") {
85100
LevelFilter::OFF
86101
} else if cfg!(feature = "max_level_error") {

0 commit comments

Comments
 (0)