Crate cursive_logger_view

Source
Expand description

§A FlexiLoggerView for cursive

This crate 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. Have a look at the demo below to see how it looks.

§Using the FlexiLoggerView

To create a FlexiLoggerView you first have to register the boxed_flexi_log_writer(&cursive) or CursiveLogWriter::new(&cursive).into_boxed() as a LogTarget in flexi_logger. After the flexi_logger has started, you may create a FlexiLoggerView::new().wrap_scroll_view() instance and add it to cursive.

use cursive::{Cursive, CursiveExt};
use cursive_logger_view::{CursiveLogWriter, FlexiLoggerView};
use flexi_logger::Logger;
    // we need to initialize cursive first, as the cursive-logger-view
    // needs a cursive callback sink to notify cursive about screen refreshs
    // when a new log message arrives
    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::info!("test log message");
    // siv.run();
use cursive::{Cursive, CursiveExt};
use cursive_logger_view::{show_flexi_logger_debug_console, hide_flexi_logger_debug_console, toggle_flexi_logger_debug_console};
use flexi_logger::Logger;
    // we need to initialize cursive first, as the cursive-logger-view
    // needs a cursive callback sink to notify cursive about screen refreshs
    // when a new log message arrives
    let mut siv = Cursive::default();

    Logger::try_with_env_or_str("trace")
        .expect("Could not create Logger from environment :(")
        .log_to_file_and_writer(
           flexi_logger::FileSpec::default()
                .directory("logs")
                .suppress_timestamp(),
            cursive_logger_view::boxed_flexi_log_writer(&siv)
        )
        .start()
        .expect("failed to initialize logger!");

    siv.add_global_callback('~', toggle_flexi_logger_debug_console);  // Bind '~' key to show/hide debug console view
    siv.add_global_callback('s', show_flexi_logger_debug_console);  // Bind 's' key to show debug console view
    siv.add_global_callback('h', hide_flexi_logger_debug_console);  // Bind 'h' key to hide debug console view

    log::info!("test log message");
    // siv.run();

Re-exports§

pub use flexi_logger;

Modules§

toggle
Add toggleable flexi_logger debug console view

Structs§

CursiveLogWriter
The flexi_logger LogWriter implementation for the FlexiLoggerView.
FlexiLoggerView
The FlexiLoggerView displays log messages from the cursive_flexi_logger log target.

Enums§

LogItems
Possible log items

Functions§

boxed_flexi_log_writer
Creates a new LogWriter instance for the FlexiLoggerView. Use this to register a cursive log writer in flexi_logger.