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
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;
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::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_flexi_logger_view::cursive_flexi_logger(&siv)
)
.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;
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::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_flexi_logger_view::cursive_flexi_logger(&siv)
)
.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§
- Cursive
LogWriter - The
flexi_loggerLogWriterimplementation for theFlexiLoggerView. - Flexi
Logger View - The
FlexiLoggerViewdisplays log messages from thecursive_flexi_loggerlog target. It is safe to create multiple instances of this struct.
Traits§
Functions§
- cursive_
flexi_ logger - Creates a new
LogWriterinstance for theFlexiLoggerView. Use this to register a cursive log writer inflexi_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.