| |
}
|
| |
}
|
| |
|
| - |
// A custom type for log output. We need this to hide log messages
|
| - |
// from output in successful tests. Cargo will hide standard output
|
| - |
// and error by default, which is what we want, but it seems this only
|
| - |
// applies to output via the `print!` family of macros. If we open a
|
| - |
// new handle for stdout or stderr, output via that handle is not
|
| - |
// captured by Cargo.
|
| - |
//
|
| - |
// Instead, we have our own log writer type that writes to stderr in
|
| - |
// production mode, and uses `print!` in tests.
|
| - |
#[derive(Default)]
|
| - |
struct LogWriter {}
|
| - |
|
| - |
#[cfg(test)]
|
| - |
impl Write for LogWriter {
|
| - |
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
|
| - |
let s = String::from_utf8_lossy(buf);
|
| - |
print!("{s}");
|
| - |
Ok(buf.len())
|
| - |
}
|
| - |
|
| - |
fn flush(&mut self) -> std::io::Result<()> {
|
| - |
Ok(())
|
| - |
}
|
| - |
}
|
| - |
|
| - |
#[cfg(not(test))]
|
| - |
impl Write for LogWriter {
|
| - |
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
|
| - |
let mut stderr = std::io::stderr();
|
| - |
stderr.write_all(buf)?;
|
| - |
stderr.flush()?;
|
| - |
Ok(buf.len())
|
| - |
}
|
| - |
|
| - |
fn flush(&mut self) -> std::io::Result<()> {
|
| - |
Ok(())
|
| - |
}
|
| - |
}
|
| - |
|
| |
pub struct Logger {
|
| |
minimum_log_level: Arc<Mutex<tracing::Level>>,
|
| |
}
|