Crate cursive_flexi_logger_view[][src]

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 cursive_flexi_logger as a LogTarget in flexi_logger. After the flexi_logger has started, you may create a FlexiLoggerView instance and add it to cursive.

use cursive::{Cursive, CursiveExt};
use cursive_flexi_logger_view::FlexiLoggerView;
use flexi_logger::{Logger, LogTarget};

fn main() {
    // we need to initialize cursive first, as the cursive-flexi-logger
    // needs a cursive callback sink to notify cursive about screen refreshs
    // when a new log message arrives
    let mut siv = Cursive::default();

    Logger::with_env_or_str("trace")
        .log_target(LogTarget::FileAndWriter(
            cursive_flexi_logger_view::cursive_flexi_logger(&siv),
        ))
        .directory("logs")
        .suppress_timestamp()
        .format(flexi_logger::colored_with_thread)
        .start()
        .expect("failed to initialize logger!");

    siv.add_layer(FlexiLoggerView::scrollable()); // omit `scrollable` to remove scrollbars

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

Look into the FlexiLoggerView documentation for a detailed explanation.

Add toggleable flexi_logger debug console view

This crate also provide utility functions, which is simplify usage of FlexiLoggerView, providing debug console view like Cursive::toggle_debug_console. There is 3 functions:

  • show_flexi_logger_debug_console: show debug console view;
  • hide_flexi_logger_debug_console: hide debug console view (if visible);
  • toggle_flexi_logger_debug_console: show the debug console view, or hide it if it’s already visible.
use cursive::{Cursive, CursiveExt};
use cursive_flexi_logger_view::{show_flexi_logger_debug_console, hide_flexi_logger_debug_console, toggle_flexi_logger_debug_console};
use flexi_logger::{Logger, LogTarget};

fn main() {
    // we need to initialize cursive first, as the cursive-flexi-logger
    // needs a cursive callback sink to notify cursive about screen refreshs
    // when a new log message arrives
    let mut siv = Cursive::default();

    Logger::with_env_or_str("trace")
        .log_target(LogTarget::FileAndWriter(
            cursive_flexi_logger_view::cursive_flexi_logger(&siv),
        ))
        .directory("logs")
        .suppress_timestamp()
        .format(flexi_logger::colored_with_thread)
        .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();
}

Structs

CursiveLogWriter

The flexi_logger LogWriter implementation for the FlexiLoggerView.

FlexiLoggerView

The FlexiLoggerView displays log messages from the cursive_flexi_logger log target. It is safe to create multiple instances of this struct.

Traits

Indentable

Functions

cursive_flexi_logger

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

hide_flexi_logger_debug_console

Hide the flexi_logger debug console (if visible).

show_flexi_logger_debug_console

Show the flexi_logger debug console.

toggle_flexi_logger_debug_console

Show the flexi_logger debug console, or hide it if it’s already visible.