Skip to content

Commit

Permalink
Accept empty log level
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Aug 11, 2014
1 parent 9c772cd commit 81241dc
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/liblog/directive.rs
Expand Up @@ -38,7 +38,7 @@ pub fn parse_logging_spec(spec: &str) -> Vec<LogDirective> {
for s in spec.split(',') {
if s.len() == 0 { continue }
let mut parts = s.split('=');
let (log_level, name) = match (parts.next(), parts.next(), parts.next()) {
let (log_level, name) = match (parts.next(), parts.next().map(|s| s.trim()), parts.next()) {
(Some(part0), None, None) => {
// if the single argument is a log-level string or number,
// treat that as a global fallback
Expand All @@ -47,6 +47,7 @@ pub fn parse_logging_spec(spec: &str) -> Vec<LogDirective> {
None => (::MAX_LOG_LEVEL, Some(part0)),
}
}
(Some(part0), Some(""), None) => (::MAX_LOG_LEVEL, Some(part0)),
(Some(part0), Some(part1), None) => {
match parse_log_level(part1) {
Some(num) => (num, Some(part0)),
Expand Down Expand Up @@ -120,6 +121,16 @@ mod tests {
assert_eq!(dirs[0].level, ::WARN);
}

#[test]
fn parse_logging_spec_empty_log_level() {
// test parse_logging_spec with '' as log level
let dirs = parse_logging_spec("crate1::mod1=wrong,crate2=");
let dirs = dirs.as_slice();
assert_eq!(dirs.len(), 1);
assert_eq!(dirs[0].name, Some("crate2".to_string()));
assert_eq!(dirs[0].level, ::MAX_LOG_LEVEL);
}

#[test]
fn parse_logging_spec_global() {
// test parse_logging_spec with no crate
Expand Down

5 comments on commit 81241dc

@bors
Copy link
Contributor

@bors bors commented on 81241dc Aug 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from pnkfelix
at nrc@81241dc

@bors
Copy link
Contributor

@bors bors commented on 81241dc Aug 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging nick29581/rust/log = 81241dc into auto

@bors
Copy link
Contributor

@bors bors commented on 81241dc Aug 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nick29581/rust/log = 81241dc merged ok, testing candidate = 6faad3e

@bors
Copy link
Contributor

@bors bors commented on 81241dc Aug 11, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 6faad3e

Please sign in to comment.