log.rs 747 B

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