Skip to content

Commit

Permalink
Support customised logfile dashboards (forks which modify src/custom/…
Browse files Browse the repository at this point in the history
…*.rs)
  • Loading branch information
happybeing committed Aug 20, 2020
1 parent b69b8f3 commit 174e97b
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 52 deletions.
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ edition = "2018"

[features]
default = ["termion"]
logtail = []

[dependencies]
rand = "0.7.3"
Expand All @@ -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"]
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down Expand Up @@ -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
Expand Down
52 changes: 20 additions & 32 deletions src/bin/logtail-termion.rs
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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::{
Expand All @@ -37,34 +45,14 @@ type TuiTerminal = tui::terminal::Terminal<TermionBackend<termion::screen::Alter

use std::fs::File;
use std::io::{BufRead, BufReader};
use structopt::StructOpt;

use futures::{
future::FutureExt, // for `.fuse()`
pin_mut,
select,
};

static MAX_CONTENT: &str = "100";


use structopt::StructOpt;

#[derive(StructOpt, Debug)]
#[structopt(about = "Monitor multiple logfiles in the terminal.")]
struct Opt {
/// Maximum number of lines to keep for each logfile
#[structopt(short = "l", long, default_value = MAX_CONTENT)]
lines_max: usize,

/// Ignore any existing logfile content
#[structopt(short, long)]
ignore_existing: bool,

/// One or more logfiles to monitor
#[structopt(name = "LOGFILE")]
files: Vec<String>,
}

#[tokio::main]
pub async fn main() -> std::io::Result<()> {
let opt = Opt::from_args();
Expand Down
6 changes: 5 additions & 1 deletion src/app.rs → src/custom/app.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/custom/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod app;
pub mod opt;
pub mod ui;
24 changes: 24 additions & 0 deletions src/custom/opt.rs
Original file line number Diff line number Diff line change
@@ -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<String>,
}

6 changes: 5 additions & 1 deletion src/ui.rs → src/custom/ui.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down
12 changes: 0 additions & 12 deletions src/lib.rs

This file was deleted.

6 changes: 6 additions & 0 deletions src/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pub mod util;

#[cfg(feature = "termion")]
pub mod event;
#[cfg(feature = "termion")]
pub use event::{Event, Events};

0 comments on commit 174e97b

Please sign in to comment.