#tui #log #logger #widget #dispatcher

tui-logger

Logger with smart widget for the tui crate

17 releases

✓ Uses Rust 2018 edition

0.3.1 Feb 9, 2019
0.3.0 Feb 9, 2019
0.2.0 Nov 10, 2018
0.1.13 May 25, 2018

#56 in Command-line interface

Download history 203/week @ 2018-12-19 52/week @ 2018-12-26 19/week @ 2019-01-02 5/week @ 2019-01-09 14/week @ 2019-01-16 27/week @ 2019-01-23 7/week @ 2019-01-30 32/week @ 2019-02-06 6/week @ 2019-02-13 9/week @ 2019-02-20 49/week @ 2019-02-27 9/week @ 2019-03-06 6/week @ 2019-03-13 71/week @ 2019-03-20 59/week @ 2019-03-27

106 downloads per month

MIT license

68KB
1.5K SLoC

Logger with smart widget for the tui crate

Build Status

Documentation

Documentation

Features

  • Logger implementation for the log crate
  • Logger enable/disable detection via hash table (avoid string compare)
  • Hot logger code only copies enabled log messages with timestamp into a circular buffer
  • Widgets/move_message() retrieve captured log messages from hot circular buffer
  • Lost message detection due to circular buffer
  • Log filtering performed on log record target
  • Simple Widgets to view logs and configure debuglevel per target
  • Smart Widget with dynamic event dispatcher for termion events (see demo code)
  • Logging of enabled logs to file
  • Event dispatcher for termion key events for smart/simple widget control
  • Allow configuration of target dependent loglevel specifically for file logging
  • Avoid duplicating of target, module and filename in every log record
  • Simultaneous modification of all targets' display/hot logging loglevel by key command

Smart Widget

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 target selector widget looks like this:

alt text

It controls:

  • Capturing of log messages by the logger
  • Selection of levels for display in the logging message view

The target selector widget consists of two columns:

  • Code EWIDT: E stands for Error, W for Warn, Info, Debug and Trace.
    • Inverted characters (EWIDT) are enabled log levels in the view
    • Normal characters show enabled capturing of a log level per target
    • If any of EWIDT are not shown, then the respective log level is not captured
  • Target of the log events can be defined in the log e.g. warn!(target: "demo", "Log message");

Event Dispatcher

In order to allow above mentioned control via key events, a dispatcher has been integrated. The dispatcher as module is independent from the backend, but the widgets are in the moment specifically only for termion. The event handler queue is dynamically built during drawing of the tui elements. This allows an easy link between complex ui layouts and the embedded widgets. This could even be used for mouse events, but this is not yet implemented.

Smart Widget Key Commands

KEY ACTION
h Toggles target selector widget
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
SPACE Toggles hiding of targets, which have logfilter set to off

Basic usage to initialize logger-system:

#[macro_use]
extern crate log;

use tui_logger::*;

fn main() {
    // Early initialization of the logger

    // Set max_log_level to Trace
    init_logger(log::LevelFilter::Trace).unwrap();

    // Set default level for unknown targets to Trace
    set_default_level(log::LevelFilter::Trace);

    // code....
}

For use of the widget please check examples/demo.rs

THANKS TO

Dependencies

~3.5MB
~53K SLoC