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 @@ -348,7 +348,7 @@ fn parse_spec(spec: &str) -> (Vec<Directive>, Option<inner::Filter>) {
348
348
}
349
349
} ;
350
350
dirs. push ( Directive {
351
- name : name. map ( |s| s. to_string ( ) ) ,
351
+ name : name. map ( |s| s. replace ( "-" , "_" ) ) ,
352
352
level : log_level,
353
353
} ) ;
354
354
}
@@ -613,4 +613,16 @@ mod tests {
613
613
assert_eq ! ( dirs[ 0 ] . level, LevelFilter :: max( ) ) ;
614
614
assert ! ( filter. is_some( ) && filter. unwrap( ) . to_string( ) == "a*c" ) ;
615
615
}
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
+ }
616
628
}
Original file line number Diff line number Diff line change 69
69
//! [2017-11-09T02:12:24Z INFO main] the answer was: 12
70
70
//! ```
71
71
//!
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`).
74
75
//!
75
76
//! ```{.bash}
76
- //! $ RUST_LOG=my_app ./my-app
77
+ //! $ RUST_LOG=my-app ./my-app
77
78
//! [2017-11-09T02:12:24Z DEBUG my_app] this is a debug message
78
79
//! [2017-11-09T02:12:24Z ERROR my_app] this is printed by default
79
80
//! [2017-11-09T02:12:24Z INFO my_app] the answer was: 12
You can’t perform that action at this time.
0 commit comments