custom_log_backend.rs 465 B

123456789101112131415161718192021222324
  1. use simple_logger::{LogBackend, SimpleLogger};
  2. struct CustomLogBackend;
  3. impl LogBackend for CustomLogBackend {
  4. fn log(&self, message: String) {
  5. println!("[Custom log backend] {}", message);
  6. }
  7. }
  8. impl CustomLogBackend {
  9. fn new() -> Box<Self> {
  10. Box::new(Self)
  11. }
  12. }
  13. fn main() {
  14. SimpleLogger::new()
  15. .with_backend(CustomLogBackend::new())
  16. .init()
  17. .unwrap();
  18. log::warn!("This is an example message.");
  19. }