threads.rs 600 B

12345678910111213141516171819202122232425
  1. use simple_logger::SimpleLogger;
  2. fn main() {
  3. SimpleLogger::new().with_threads(true).init().unwrap();
  4. log::info!("Main thread logs here.");
  5. // If the "nightly" feature is enabled, the output will include thread ids.
  6. for _ in 1..=5 {
  7. std::thread::spawn(|| {
  8. log::info!("Unnamed thread logs here.");
  9. })
  10. .join()
  11. .unwrap();
  12. }
  13. std::thread::Builder::new()
  14. .name("named_thread".to_string())
  15. .spawn(|| {
  16. log::info!("Named thread logs here.");
  17. })
  18. .unwrap()
  19. .join()
  20. .unwrap();
  21. }