Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/liblog/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ pub fn log(level: u32, loc: &'static LogLocation, args: &fmt::Arguments) {
// Test the literal string from args against the current filter, if there
// is one.
match unsafe { FILTER.as_ref() } {
Some(filter) if filter.is_match(args.to_string().as_slice()) => return,
Some(filter) if !filter.is_match(args.to_string().as_slice()) => return,
_ => {}
}

Expand Down Expand Up @@ -383,7 +383,7 @@ fn enabled(level: u32,

/// Initialize logging for the current process.
///
/// This is not threadsafe at all, so initialization os performed through a
/// This is not threadsafe at all, so initialization is performed through a
/// `Once` primitive (and this function is called from that primitive).
fn init() {
let (mut directives, filter) = match os::getenv("RUST_LOG") {
Expand Down
54 changes: 54 additions & 0 deletions src/test/run-pass/rust-log-filter.rs
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());
}