cursive-logger-view

Crates.iocursive-logger-view
lib.rscursive-logger-view
version0.8.4
created_at2024-03-08 02:07:29.460199+00
updated_at2025-03-31 21:35:25.497787+00
descriptionForked from deinstapel/cursive-logger-view-view
homepage
repositoryhttps://github.com/2moe/cursive-logger-view
max_upload_size
id1166431
size61,954
Moe (2moe)

documentation

https://docs.rs/cursive-logger-view

README

cursive-logger-view

crates.io doc

A fork of cursive-logger-view-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.

Commit count: 56

cargo fmt