Skip to content

Commit 4ecc111

Browse files
committed
support kebab-case names in parse sepc
1 parent b8c3754 commit 4ecc111

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

src/filter/mod.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ fn parse_spec(spec: &str) -> (Vec<Directive>, Option<inner::Filter>) {
348348
}
349349
};
350350
dirs.push(Directive {
351-
name: name.map(|s| s.to_string()),
351+
name: name.map(|s| s.replace("-", "_")),
352352
level: log_level,
353353
});
354354
}
@@ -613,4 +613,16 @@ mod tests {
613613
assert_eq!(dirs[0].level, LevelFilter::max());
614614
assert!(filter.is_some() && filter.unwrap().to_string() == "a*c");
615615
}
616+
617+
#[test]
618+
fn parse_spec_name_canonicalization() {
619+
// accept binary names in both styles (`snake_case` and `kebab-case`)
620+
let (dirs, _) = parse_spec("snake_case_crate=info,kebaba-case-crate=debug");
621+
assert_eq!(dirs.len(), 2);
622+
assert_eq!(dirs[0].name, Some("snake_case_crate".to_string()));
623+
assert_eq!(dirs[0].level, LevelFilter::Info);
624+
625+
assert_eq!(dirs[1].name, Some("kebaba_case_crate".to_string()));
626+
assert_eq!(dirs[1].level, LevelFilter::Debug);
627+
}
616628
}

src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,12 @@
6969
//! [2017-11-09T02:12:24Z INFO main] the answer was: 12
7070
//! ```
7171
//!
72-
//! If the binary name contains hyphens, you will need to replace
73-
//! them with underscores:
72+
//! Some package names may contain hyphens, this logger does the conversion for
73+
//! you so you don't have to. You are free to use the original form (`my-app`)
74+
//! or the canonical form (`my_app`).
7475
//!
7576
//! ```{.bash}
76-
//! $ RUST_LOG=my_app ./my-app
77+
//! $ RUST_LOG=my-app ./my-app
7778
//! [2017-11-09T02:12:24Z DEBUG my_app] this is a debug message
7879
//! [2017-11-09T02:12:24Z ERROR my_app] this is printed by default
7980
//! [2017-11-09T02:12:24Z INFO my_app] the answer was: 12

0 commit comments

Comments
 (0)