diff --git a/src/filter/mod.rs b/src/filter/mod.rs index 8f7787f0..5ca0dbed 100644 --- a/src/filter/mod.rs +++ b/src/filter/mod.rs @@ -299,6 +299,7 @@ fn parse_spec(spec: &str) -> (Vec, Option) { return (dirs, None); } if let Some(m) = mods { + let m = m.replace("-", "_"); for s in m.split(',').map(|ss| ss.trim()) { if s.is_empty() { continue; @@ -697,6 +698,21 @@ mod tests { assert!(filter.is_none()); } + #[test] + fn parse_spec_replaces_hyphens_in_mods() { + let (dirs, filter) = parse_spec("my-crate1::mod1=error,crate1::mod2,my-crate2=debug"); + assert_eq!(dirs.len(), 3); + assert_eq!(dirs[0].name, Some("my_crate1::mod1".to_string())); + assert_eq!(dirs[0].level, LevelFilter::Error); + + assert_eq!(dirs[1].name, Some("crate1::mod2".to_string())); + assert_eq!(dirs[1].level, LevelFilter::max()); + + assert_eq!(dirs[2].name, Some("my_crate2".to_string())); + assert_eq!(dirs[2].level, LevelFilter::Debug); + assert!(filter.is_none()); + } + #[test] fn parse_spec_invalid_crate() { // test parse_spec with multiple = in specification diff --git a/src/lib.rs b/src/lib.rs index 31ea7c3d..3301216b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -71,8 +71,8 @@ //! [2017-11-09T02:12:24Z INFO main] the answer was: 12 //! ``` //! -//! If the binary name contains hyphens, you will need to replace -//! them with underscores: +//! If the binary name contains hyphens, they need to be replaced with underscores. +//! The library handles this case automatically, in case you forget: //! //! ```{.bash} //! $ RUST_LOG=my_app ./my-app