Create log files and admins can visualize them in the dev page #4

Closed
opened 2025-04-08 17:55:23 +02:00 by gburri · 1 comment
Owner
See https://docs.rs/tracing-subscriber/0.3.19/tracing_subscriber/fmt/writer/trait.MakeWriter.html Create log files in *data/logs*? Depend on #3
gburri added the
Kind/Feature
label 2025-04-08 17:55:23 +02:00
Author
Owner

Use crate tracing-appender:

    // Create a file appender with daily rotation
    let file_appender = RollingFileAppender::new(
        Rotation::DAILY,
        Path::new("logs"),  // Directory
        "application.log",  // Base filename
    );
    
    // Create a non-blocking writer
    let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender);
    
    // Store the guard in a static or global variable to keep it alive
    // or have your main function take ownership of it
    
    tracing_subscriber::registry()
        .with(fmt::layer().with_writer(non_blocking))    // File output
        .init();

Code updated by aebca7a7e2

Use crate tracing-appender: ``` rust // Create a file appender with daily rotation let file_appender = RollingFileAppender::new( Rotation::DAILY, Path::new("logs"), // Directory "application.log", // Base filename ); // Create a non-blocking writer let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender); // Store the guard in a static or global variable to keep it alive // or have your main function take ownership of it tracing_subscriber::registry() .with(fmt::layer().with_writer(non_blocking)) // File output .init(); ``` Code updated by aebca7a7e2
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: gburri/recipes#4
No description provided.