|
|
@ -100,7 +100,7 @@ impl<'a, L: Logger> Logger for FilteringLogger<'a, L> { |
|
|
|
|
|
|
|
#[derive(Debug, Default)]
|
|
|
|
pub struct StoringLogger {
|
|
|
|
log: RefCell<Vec<Entry<String>>>,
|
|
|
|
log: RefCell<(bool, Vec<Entry<String>>)>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl StoringLogger {
|
|
|
@ -109,21 +109,28 @@ impl StoringLogger { |
|
|
|
}
|
|
|
|
|
|
|
|
pub fn release(self) -> Vec<Entry<String>> {
|
|
|
|
self.log.into_inner()
|
|
|
|
self.log.into_inner().1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Logger for StoringLogger {
|
|
|
|
fn write<S: AsRef<str> + Into<String>>(&self, level: Level, line: S) {
|
|
|
|
let mut log = self.log.borrow_mut();
|
|
|
|
let entry = log
|
|
|
|
.pop()
|
|
|
|
.map(|e| Entry(min(e.0, level), e.1 + line.as_ref()))
|
|
|
|
.unwrap_or_else(|| Entry(level, line.into()));
|
|
|
|
log.push(entry);
|
|
|
|
let entry = if log.0 {
|
|
|
|
log
|
|
|
|
.1
|
|
|
|
.pop()
|
|
|
|
.map(|e| Entry(min(e.0, level), e.1 + line.as_ref()))
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
.unwrap_or_else(|| Entry(level, line.into()));
|
|
|
|
log.1.push(entry);
|
|
|
|
}
|
|
|
|
fn writeln<S: AsRef<str> + Into<String>>(&self, level: Level, line: S) {
|
|
|
|
self.log.borrow_mut().push(Entry(level, line.into()));
|
|
|
|
let mut log = self.log.borrow_mut();
|
|
|
|
log.0 = false;
|
|
|
|
log.1.push(Entry(level, line.into()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|