custom_format/
custom_format.rs

1use hackerlog::*;
2use std::thread;
3
4fn main() {
5    // Try different built-in formats
6    logger().use_simple_format();
7    info!("Simple format");
8    warn!("Just symbol and message");
9
10    // Detailed format with timestamp
11    logger().use_detailed_format();
12    info!("Detailed format");
13    error!("With timestamp");
14
15    // Debug format with file location
16    logger().use_debug_format();
17    info!("Debug format");
18    warn!("With file location");
19
20    // Custom format
21    logger().set_format("{datetime} | {pid}:{thread_id} | {level} | {message}");
22    info!("Custom format");
23
24    // Format with context
25    let _ctx = logger().add_context("user", "admin");
26    logger().set_format("[{level}] {context}{message} ({file}:{line})");
27    info!("Message with context");
28
29    // Complex format showing all options
30    logger().set_format(concat!(
31        "Time: {time} | ",
32        "Date: {date} | ",
33        "Thread: {thread} | ",
34        "PID: {pid} | ",
35        "Level: {level} ({symbol}) | ",
36        "{context}",
37        "Message: {message}"
38    ));
39
40    thread::spawn(|| {
41        info!("Shows all available placeholders");
42    })
43    .join()
44    .unwrap();
45}