log.rs 701 B

12345678910111213141516171819202122232425
  1. use chrono;
  2. use env_logger;
  3. use std::io::Write;
  4. pub trait BuilderExt {
  5. /// Uses a standard format for log messages which includes the source file and line number
  6. /// a logging statement occurred on.
  7. fn btformat(&mut self) -> &mut Self;
  8. }
  9. impl BuilderExt for env_logger::Builder {
  10. fn btformat(&mut self) -> &mut Self {
  11. self.format(|fmt, record| {
  12. writeln!(
  13. fmt,
  14. "[{} {} {}:{}] {}",
  15. chrono::Utc::now().to_rfc3339(),
  16. record.level(),
  17. record.file().unwrap_or("(unknown)"),
  18. record.line().unwrap_or(u32::MAX),
  19. record.args(),
  20. )
  21. })
  22. }
  23. }