[][src]Crate tui_logger

Logger with smart widget for the tui crate

Build Status

Demo of the widget

alt

Documentation

Documentation

Features

  • [X] Logger implementation for the log crate
  • [X] Logger enable/disable detection via hash table (avoid string compare)
  • [X] Hot logger code only copies enabled log messages with timestamp into a circular buffer
  • [X] Widgets/move_message() retrieve captured log messages from hot circular buffer
  • [X] Lost message detection due to circular buffer
  • [X] Log filtering performed on log record target
  • [X] Simple Widgets to view logs and configure debuglevel per target
  • [X] Smart Widget with dynamic event dispatcher for termion events (see demo code)
  • [X] Logging of enabled logs to file
  • [X] 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

KEYACTION
hToggles target selector widget
UPSelect previous target in target selector widget
DOWNSelect next target in target selector widget
LEFTReduce SHOWN (!) log messages by one level
RIGHTIncrease SHOWN (!) log messages by one level
-Reduce CAPTURED (!) log messages by one level
+Increase CAPTURED (!) log messages by one level
SPACEToggles 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
    tui_logger::init_logger(log::LevelFilter::Trace).unwrap();

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

    // code....
}

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

Structs

CircularBuffer

CircularBuffer is used to store the last elements of an endless sequence. Oldest elements will be overwritten. The implementation focus on speed. So memory allocations are avoided.

Dispatcher

Dispatcher is used to dispatch any event to a dynamically built chain of handlers. The dispatch is a one-shot event. After an event is successfully processed, the dispatch chain is emptied.

LevelConfig

LevelConfig stores the relation target->LevelFilter in a hash table.

TuiLoggerSmartWidget

The Smart Widget combines the TuiLoggerWidget and the TuiLoggerTargetWidget into a nice combo, where the TuiLoggerTargetWidget can be shown/hidden.

TuiLoggerTargetWidget

This is the definition for the TuiLoggerTargetWidget, which allows configuration of the logger system and selection of log messages. It implements the EventListener trait, because it can enter event handlers to the dispatcher for the key commands.

TuiLoggerWidget

The TuiLoggerWidget shows the logging messages in an endless scrolling view. It is controlled by a TuiWidgetState for selected events.

TuiWidgetState

This struct contains the shared state of a TuiLoggerWidget and a TuiLoggerTargetWidget.

Traits

EventListener

The EventListener Trait is only a standard way to implement a tui widget, which can listen to events.

Functions

init_logger

Init the logger and record with log crate.

move_events

Move events from hot circular buffer to the main one. If defined, log records will be written to file.

set_default_level

Set default levelfilter for unknown targets of the logger

set_hot_buffer_depth

Set the depth of the hot buffer in order to avoid message loss. This is effective only after a call to move_events()

set_level_for_target

Set levelfilter for a specific target in the logger

set_log_file

Define filename for logging.