Skip to content

Commit 9c2fc3a

Browse files
committed
support kebab-case names in parse sepc
1 parent 8ef1615 commit 9c2fc3a

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
@@ -336,7 +336,7 @@ fn parse_spec(spec: &str) -> (Vec<Directive>, Option<inner::Filter>) {
336336
}
337337
};
338338
dirs.push(Directive {
339-
name: name.map(|s| s.to_string()),
339+
name: name.map(|s| s.replace("-", "_")),
340340
level: log_level,
341341
});
342342
}
@@ -860,4 +860,16 @@ mod tests {
860860
assert_eq!(dirs[0].level, LevelFilter::max());
861861
assert!(filter.is_some() && filter.unwrap().to_string() == "a*c");
862862
}
863+
864+
#[test]
865+
fn parse_spec_name_canonicalization() {
866+
// accept binary names in both styles (`snake_case` and `kebab-case`)
867+
let (dirs, _) = parse_spec("snake_case_crate=info,kebaba-case-crate=debug");
868+
assert_eq!(dirs.len(), 2);
869+
assert_eq!(dirs[0].name, Some("snake_case_crate".to_string()));
870+
assert_eq!(dirs[0].level, LevelFilter::Info);
871+
872+
assert_eq!(dirs[1].name, Some("kebaba_case_crate".to_string()));
873+
assert_eq!(dirs[1].level, LevelFilter::Debug);
874+
}
863875
}

src/lib.rs

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

0 commit comments

Comments
 (0)