use std::io::{self, Write};
use ticklog::{error, info, warn, Level, LogSink};
struct MarkerSink {
count: u64,
}
impl LogSink for MarkerSink {
fn accept(&mut self, line: &[u8], level: Level) -> io::Result<()> {
self.count += 1;
let mut out = io::stdout().lock();
write!(out, "[custom #{} {:?}] ", self.count, level)?;
out.write_all(line)?;
out.write_all(b"\n")
}
}
fn main() {
let guard = ticklog::builder()
.sink(MarkerSink { count: 0 })
.max_level(Level::Trace) .build()
.expect("ticklog builds once per process");
info!("listening on {}", 8080);
warn!("disk {}% full", 91);
error!("query failed: {}", "timeout");
drop(guard);
}