forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auto merge of rust-lang#17331 : kballard/rust/rust_log_pattern_invert…
…ed, r=alexcrichton RUST_LOG supports regex filtering of log messages with a syntax like `RUST_LOG=main/foo` to use the regex filter 'foo'. Unfortunately, the filter was inverted, so `RUST_LOG=main/foo` would actually show all messages except the ones containing 'foo'.
- Loading branch information
Showing
2 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// exec-env:RUST_LOG=rust-log-filter/f.o | ||
|
||
#![feature(phase)] | ||
#[phase(plugin,link)] | ||
extern crate log; | ||
|
||
pub struct ChannelLogger { | ||
tx: Sender<String> | ||
} | ||
|
||
impl ChannelLogger { | ||
pub fn new() -> (Box<ChannelLogger>, Receiver<String>) { | ||
let (tx, rx) = channel(); | ||
(box ChannelLogger { tx: tx }, rx) | ||
} | ||
} | ||
|
||
impl log::Logger for ChannelLogger { | ||
fn log(&mut self, record: &log::LogRecord) { | ||
self.tx.send(format!("{}", record.args)); | ||
} | ||
} | ||
|
||
pub fn main() { | ||
let (logger, rx) = ChannelLogger::new(); | ||
|
||
spawn(proc() { | ||
log::set_logger(logger); | ||
|
||
// our regex is "f.o" | ||
// ensure it is a regex, and isn't anchored | ||
info!("foo"); | ||
info!("bar"); | ||
info!("foo bar"); | ||
info!("bar foo"); | ||
info!("f1o"); | ||
}); | ||
|
||
assert_eq!(rx.recv().as_slice(), "foo"); | ||
assert_eq!(rx.recv().as_slice(), "foo bar"); | ||
assert_eq!(rx.recv().as_slice(), "bar foo"); | ||
assert_eq!(rx.recv().as_slice(), "f1o"); | ||
assert!(rx.recv_opt().is_err()); | ||
} |