Crate tui_logger [−] [src]
Logger with smart widget for the tui
crate.
Demo of the widget:
Features:
- [X] Logger implementation for the
log
crate - [X] Logger enable/disable detection uses fast, collision free hash table
- [ ] Collision free hash table algorithm to be done. Currently use a big table
- [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 of overwritten logs messages in circular buffer
- [X] Log filtering performed on log-target
- [X] Simple Widgets to view the logs and select Debuglevel of target
- [X] Smart Widget with dynamic event dispatcher for
termion
events (see demo code) - [X] Logging of enabled logs to file
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 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 shows enabled capturing of a log level
- If any of EWIDT are not shown, then the repective log level is not captured
- Target of the log events e.g.
warn!(target: "demo", "Log message");
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:
extern crate log; extern crate tui_logger; use log::LevelFilter; use tui_logger::*; fn main() { // Early initialization of the logger // Set max_log_level to Trace init_logger(LevelFilter::Trace).unwrap(); // Set default level for unknown targets to Trace set_default_level(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 overwrittten. The implementation focus on speed. So memory allocations are avoided. |
Dispatcher |
Dispatcher is used to dispatch any termion event to a dynamically built chain of handlers. The dispatch is a one-shot event. After an event is processed, the dispatch chain is empty. |
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 |
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_level_for_target |
Set levelfilter for a specific target in the logger |
set_log_file |
Define filename for logging. |