# Logger with smart widget for the tui
and ratatui
crate
## Demo of the widget
## Documentation
## Features
log
crateslog
support, providing a Drain to integrate into your slog
infrastructuretracing
support[ ] Simultaneous modification of all targets' display/hot logging loglevel by key command
Smart widget consists of two widgets. Left is the target selector widget and on the right side the logging messages view scrolling up. The target selector widget can be hidden/shown during runtime via key command. The key command to be provided to the TuiLoggerWidget via transition() function.
The target selector widget looks like this:
It controls:
Capturing of log messages by the logger
Selection of levels for display in the logging message view
The two columns have the following meaning:
Code EWIDT: E stands for Error, W for Warn, Info, Debug and Trace.
Target of the log events can be defined in the log e.g. warn!(target: "demo", "Log message");
ignore
| KEY | ACTION
|----------|-----------------------------------------------------------|
| h | Toggles target selector widget hidden/visible
| f | Toggle focus on the selected target only
| UP | Select previous target in target selector widget
| DOWN | Select next target in target selector widget
| LEFT | Reduce SHOWN (!) log messages by one level
| RIGHT | Increase SHOWN (!) log messages by one level
| - | Reduce CAPTURED (!) log messages by one level
| + | Increase CAPTURED (!) log messages by one level
| PAGEUP | Enter Page Mode and scroll approx. half page up in log history.
| PAGEDOWN | Only in page mode: scroll 10 events down in log history.
| ESCAPE | Exit page mode and go back to scrolling mode
| SPACE | Toggles hiding of targets, which have logfilter set to off
The mapping of key to action has to be done in the application. The respective TuiWidgetEvent has to be provided to TuiWidgetState::transition().
Remark to the page mode: The timestamp of the event at event history's bottom line is used as reference. This means, changing the filters in the EWIDT/focus from the target selector window should work as expected without jumps in the history. The page next/forward advances as per visibility of the events.
```rust
extern crate log; //use tui_logger;
fn main() { // Early initialization of the logger
// Set maxloglevel to Trace tuilogger::initlogger(log::LevelFilter::Trace).unwrap();
// Set default level for unknown targets to Trace tuilogger::setdefault_level(log::LevelFilter::Trace);
// code.... } ```
For use of the widget please check examples/demo.rs
The demo does not support another terminal backend besides termion. During build the termion feature of tui needs to be enabled
Run demo with tui and termion:
cargo run --example demo --no-default-features -F tui-rs,tui/termion
or simply:
cargo run --example demo
Run demo with ratatui and termion:
cargo run --example demo --no-default-features -F ratatui-support,ratatui/termion
slog
supporttui-logger
provides a TuiSlogDrain which implements slog::Drain
and will route all records
it receives to the tui-logger
widget.
Enabled by feature "slog-support"
tracing-subscriber
supporttui-logger
provides a TuiTracingSubscriberLayer which implements
tracing_subscriber::Layer
and will collect all events
it receives to the tui-logger
widget
Enabled by feature "tracing-support"
ratatui
supportEnabled by feature "ratatui-support" + disable default-features of tui-logger
```rust
extern crate log; //use tuilogger; use envlogger;
fn main() {
// Early initialization of the logger
let drain = tuilogger::Drain::new();
// instead of tuilogger::initlogger, we use env_logger
envlogger::Builder::default()
.format(move |buf, record|
// patch the env-logger entry through our drain to the tui-logger
Ok(drain.log(record))
).init(); // make this the global logger
// code....
}
```
Florian Dehau for his great crate tui-rs