File: threads.rs

package info (click to toggle)
rust-simple-logger 5.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 220 kB
  • sloc: makefile: 4
file content (25 lines) | stat: -rw-r--r-- 600 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use simple_logger::SimpleLogger;

fn main() {
    SimpleLogger::new().with_threads(true).init().unwrap();

    log::info!("Main thread logs here.");

    // If the "nightly" feature is enabled, the output will include thread ids.
    for _ in 1..=5 {
        std::thread::spawn(|| {
            log::info!("Unnamed thread logs here.");
        })
        .join()
        .unwrap();
    }

    std::thread::Builder::new()
        .name("named_thread".to_string())
        .spawn(|| {
            log::info!("Named thread logs here.");
        })
        .unwrap()
        .join()
        .unwrap();
}