File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -336,7 +336,7 @@ fn parse_spec(spec: &str) -> (Vec<Directive>, Option<inner::Filter>) {
336
336
}
337
337
} ;
338
338
dirs. push ( Directive {
339
- name : name. map ( |s| s. to_string ( ) ) ,
339
+ name : name. map ( |s| s. replace ( "-" , "_" ) ) ,
340
340
level : log_level,
341
341
} ) ;
342
342
}
@@ -860,4 +860,16 @@ mod tests {
860
860
assert_eq ! ( dirs[ 0 ] . level, LevelFilter :: max( ) ) ;
861
861
assert ! ( filter. is_some( ) && filter. unwrap( ) . to_string( ) == "a*c" ) ;
862
862
}
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
+ }
863
875
}
Original file line number Diff line number Diff line change 71
71
//! [2017-11-09T02:12:24Z INFO main] the answer was: 12
72
72
//! ```
73
73
//!
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`).
76
77
//!
77
78
//! ```{.bash}
78
- //! $ RUST_LOG=my_app ./my-app
79
+ //! $ RUST_LOG=my-app ./my-app
79
80
//! [2017-11-09T02:12:24Z DEBUG my_app] this is a debug message
80
81
//! [2017-11-09T02:12:24Z ERROR my_app] this is printed by default
81
82
//! [2017-11-09T02:12:24Z INFO my_app] the answer was: 12
You can’t perform that action at this time.
0 commit comments