auto merge of #13912 : seanmonstar/rust/logrecord, r=alexcrichton

The logging macros now create a LogRecord, and pass that to the Logger. This will allow custom loggers to change the formatting, and possible filter on more properties of the log record.

DefaultLogger's formatting was taken from Python's default formatting:
`LEVEL:from: message`

Also included: fmt::Arguments now implement Show, so they can be used to
extend format strings.

@alexcrichton r?
This commit is contained in:
bors 2014-05-05 15:26:31 -07:00
commit 7583544fb5
6 changed files with 92 additions and 16 deletions

View file

@ -19,14 +19,14 @@ extern crate native;
use std::fmt;
use std::io::{ChanReader, ChanWriter};
use log::{set_logger, Logger};
use log::{set_logger, Logger, LogRecord};
struct MyWriter(ChanWriter);
impl Logger for MyWriter {
fn log(&mut self, _level: u32, args: &fmt::Arguments) {
fn log(&mut self, record: &LogRecord) {
let MyWriter(ref mut inner) = *self;
fmt::writeln(inner as &mut Writer, args);
fmt::writeln(inner as &mut Writer, record.args);
}
}

View file

@ -33,7 +33,7 @@ impl fmt::Signed for B {
}
}
macro_rules! t(($a:expr, $b:expr) => { assert_eq!($a, $b.to_owned()) })
macro_rules! t(($a:expr, $b:expr) => { assert_eq!($a.as_slice(), $b) })
pub fn main() {
// Make sure there's a poly formatter that takes anything
@ -202,6 +202,10 @@ fn test_format_args() {
let s = format_args!(fmt::format, "hello {}", "world");
t!(s, "hello world");
let s = format_args!(|args| {
format!("{}: {}", "args were", args)
}, "hello {}", "world");
t!(s, "args were: hello world");
}
fn test_order() {