From 174e97b6ca9ca332b969e51321d57faa8b2edb1d Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 20 Aug 2020 20:47:23 +0100 Subject: [PATCH] Support customised logfile dashboards (forks which modify src/custom/*.rs) --- Cargo.toml | 5 ++-- README.md | 18 ++++++++++--- src/bin/logtail-termion.rs | 52 +++++++++++++++----------------------- src/{ => custom}/app.rs | 6 ++++- src/custom/mod.rs | 3 +++ src/custom/opt.rs | 24 ++++++++++++++++++ src/{ => custom}/ui.rs | 6 ++++- src/lib.rs | 12 --------- src/mod.rs | 6 +++++ 9 files changed, 80 insertions(+), 52 deletions(-) rename src/{ => custom}/app.rs (93%) create mode 100644 src/custom/mod.rs create mode 100644 src/custom/opt.rs rename src/{ => custom}/ui.rs (94%) delete mode 100644 src/lib.rs create mode 100644 src/mod.rs diff --git a/Cargo.toml b/Cargo.toml index ac53764..22bbf7b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,6 @@ edition = "2018" [features] default = ["termion"] -logtail = [] [dependencies] rand = "0.7.3" @@ -32,9 +31,9 @@ crossterm = { version = "0.17", optional = true } [[bin]] name = "logtail" -required-features = ["termion", "logtail"] +required-features = ["termion"] path = "src/bin/logtail-termion.rs" [[bin]] name = "logtail-crossterm" -required-features = ["crossterm", "logtail"] +required-features = ["crossterm"] diff --git a/README.md b/README.md index dc853f6..7b1539b 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,6 @@ The command is written in Rust and uses [tui-rs](https://github.com/fdehau/tui-rs) to create the terminal UI, and [linemux](https://github.com/jmagnuson/linemux) to monitor the logfiles. -Note: `vdash` is a fork of `logtail` that provides a dashboard for SAFE Network Vaults (see [vdash](https://github.com/theWebalyst/vdash)). - - ## Operating Systems - **Linux:** works on Ubuntu. - **MacOS:** may 'just work' but has not been tested - please do! @@ -35,6 +32,21 @@ For more information: logtail --help +## Customised Logfile Dashboards + +If you want to use the core functionality of logtail-dash to create +a customised terminal display based on real time updates to files +you can do this by creating a fork, and customising the following +files in src/custom: + +`src/custom/opt.rs`: command line options and usage + +`src/custom/app.rs`: application logic (e.g. parsing logfiles to `dashboard state) + +`src/custom/ui.rs `: dashboard display and keyboard/mouse interface + +Example: `vdash` is a fork of `logtail` that provides a dashboard for SAFE Network Vaults (see [vdash](https://github.com/theWebalyst/vdash)). + ## Build ### Get pre-requisites 1. **Get Rust:** see: https://doc.rust-lang.org/cargo/getting-started/installation.html diff --git a/src/bin/logtail-termion.rs b/src/bin/logtail-termion.rs index 12f1988..ec94d35 100644 --- a/src/bin/logtail-termion.rs +++ b/src/bin/logtail-termion.rs @@ -1,13 +1,13 @@ -//! logtail is a logfile monitoring dashboard in the terminal +//! This app monitors and logfiles and displays status in the terminal //! -//! Displays and updates a dashboard based on one or more logfiles -//! -//! Example: -//! logtail /var/log/auth.log /var/log/kern.log +//! It is based on logtail-dash, which is a basic logfile dashboard +//! and also a framework for similar apps with customised dahsboard +//! displays. //! -//! Press 'v' and 'h' for a vertical or horizontal layout. +//! Custom apps based on logtail can be created by creating a +//! fork of logtail-dash and modifying the files in src/custom //! -//! See README or try `logtail -h` for more information. +//! See README for more information. #![recursion_limit="256"] // Prevent select! macro blowing up @@ -17,10 +17,18 @@ use std::collections::HashMap; use linemux::MuxedLines; use tokio::stream::StreamExt; -use logtail::ui::{draw_dashboard}; -use logtail::app::{DashState, LogMonitor, DashViewMain}; -use logtail::event::{Event, Events}; -use logtail::util::{StatefulList}; +///! forks of logterm customise the files in src/custom +#[path = "../custom/mod.rs"] +pub mod custom; +use self::custom::app::{DashState, LogMonitor, DashViewMain}; +use self::custom::opt::{Opt}; +use self::custom::ui::{draw_dashboard}; + +///! logtail and its forks share code in src/ +#[path = "../mod.rs"] +pub mod shared; +use shared::event::{Event, Events}; +use crate::shared::util::{StatefulList}; use termion::{event::Key, input::MouseTerminal, raw::IntoRawMode, screen::AlternateScreen}; use tui::{ @@ -37,6 +45,7 @@ type TuiTerminal = tui::terminal::Terminal, -} - #[tokio::main] pub async fn main() -> std::io::Result<()> { let opt = Opt::from_args(); diff --git a/src/app.rs b/src/custom/app.rs similarity index 93% rename from src/app.rs rename to src/custom/app.rs index b60f337..1ecc0ec 100644 --- a/src/app.rs +++ b/src/custom/app.rs @@ -1,6 +1,10 @@ +///! Application logic +///! +///! Edit src/custom/app.rs to create a customised fork of logtail-dash + use std::fs::File; -use crate::util::{StatefulList}; +use crate::shared::util::{StatefulList}; pub struct LogMonitor { pub index: usize, diff --git a/src/custom/mod.rs b/src/custom/mod.rs new file mode 100644 index 0000000..7000adf --- /dev/null +++ b/src/custom/mod.rs @@ -0,0 +1,3 @@ +pub mod app; +pub mod opt; +pub mod ui; diff --git a/src/custom/opt.rs b/src/custom/opt.rs new file mode 100644 index 0000000..86a3474 --- /dev/null +++ b/src/custom/opt.rs @@ -0,0 +1,24 @@ +///! Command line options and usage +///! +///! Edit src/custom/opt.rs to create a customised fork of logtail-dash + +static MAX_CONTENT: &str = "100"; + +pub use structopt::StructOpt; + +#[derive(StructOpt, Debug)] +#[structopt(about = "Monitor multiple logfiles in the terminal.")] +pub struct Opt { + /// Maximum number of lines to keep for each logfile + #[structopt(short = "l", long, default_value = MAX_CONTENT)] + pub lines_max: usize, + + /// Ignore any existing logfile content + #[structopt(short, long)] + pub ignore_existing: bool, + + /// One or more logfiles to monitor + #[structopt(name = "LOGFILE")] + pub files: Vec, +} + diff --git a/src/ui.rs b/src/custom/ui.rs similarity index 94% rename from src/ui.rs rename to src/custom/ui.rs index bb26bba..e3abc9d 100644 --- a/src/ui.rs +++ b/src/custom/ui.rs @@ -1,4 +1,8 @@ -use crate::app::{DashState, LogMonitor, DashViewMain}; +///! Terminal based interface and dashboard +///! +///! Edit src/custom/ui.rs to create a customised fork of logtail-dash + +use super::app::{DashState, LogMonitor, DashViewMain}; use std::collections::HashMap; use tui::{ diff --git a/src/lib.rs b/src/lib.rs deleted file mode 100644 index 0b2be84..0000000 --- a/src/lib.rs +++ /dev/null @@ -1,12 +0,0 @@ -pub mod app; -pub mod ui; -pub mod util; - -pub use app::{DashState, LogMonitor, DashViewMain}; -pub use ui::{draw_dashboard}; -pub use util::StatefulList; - -#[cfg(feature = "termion")] -pub mod event; -#[cfg(feature = "termion")] -pub use event::{Event, Events}; \ No newline at end of file diff --git a/src/mod.rs b/src/mod.rs new file mode 100644 index 0000000..b131122 --- /dev/null +++ b/src/mod.rs @@ -0,0 +1,6 @@ +pub mod util; + +#[cfg(feature = "termion")] +pub mod event; +#[cfg(feature = "termion")] +pub use event::{Event, Events};