4 releases

new 0.8.3 Feb 17, 2025
0.8.2 Feb 17, 2025
0.7.0 Jan 24, 2025
0.6.0 Mar 8, 2024

#320 in Debugging

Download history 1/week @ 2024-10-29 1/week @ 2024-11-05 3/week @ 2024-12-10 105/week @ 2025-01-21 7/week @ 2025-01-28 14/week @ 2025-02-04

126 downloads per month

BSD-3-Clause

28KB
334 lines

cursive-logger-view

crates.io doc

A fork of cursive-flexi-logger-view.


This project provides a new debug view for gyscos/cursive using the emabee/flexi_logger crate. This enables the FlexiLoggerView to respect the RUST_LOG environment variable as well as the flexi_logger configuration file.

demo

Usage

Simply add dependencies

cargo add log flexi_logger cursive cursive_logger_view

Using the FlexiLoggerView

use cursive_logger_view::{CursiveLogWriter, FlexiLoggerView};
use flexi_logger::Logger;

fn main() {
    // Initialize the Cursive TUI (Terminal User Interface) instance
    let mut siv = cursive::default();

    // Configure the flexi logger with environment-variable($RUST_LOG) or fallback to "trace" level
    Logger::try_with_env_or_str("trace")
        .expect("Could not create Logger from environment :(")
        // Configure logging to both file and Cursive
        .log_to_file_and_writer(
            // File configuration: store logs in 'logs' directory without timestamps
            flexi_logger::FileSpec::default()
                .directory("logs")
                .suppress_timestamp(),
            // Create Cursive log writer and box it for dynamic dispatch
            CursiveLogWriter::new(&siv)
                //// Optional format configuration (commented out example)
                // .with_format({
                //     use cursive_logger_view::LogItems::*;
                //     [Level, DateTime, ModLine, Message]
                //         .into_iter()
                //         .collect()
                // })
                // .with_time_format("%T%.6f".into())
                .into_boxed(),
        )
        .start()
        .expect("failed to initialize logger!");

    // Add the logger view to Cursive
    siv.add_layer(
        FlexiLoggerView::new()
            // .with_indent(true)  // Optional indentation configuration
            //
            .wrap_scroll_view(),
    );

    log::debug!("x: 42");
    log::info!("Foo\nBar"); // Info level with multi-line content
    log::error!("Failed to open file");

    siv.run()
}

Look into the documentation for a detailed explanation on the API.

Dependencies

~9–15MB
~192K SLoC