CLI Configuration & Flags
Relevant source files
The following files were used as context for generating this wiki page:
LogUtil provides a robust Command Line Interface (CLI) designed for both direct execution and an interactive configuration experience. The system leverages the structopt crate for argument parsing and includes an internal state management system for interactive file and setting selection.
Introduction
The LogUtil CLI serves as the entry point for real-time Nginx log analysis. It is designed to handle two primary workflows: Direct Mode, where users provide parameters via command-line flags for immediate execution, and Interactive Mode, which is triggered when no file path is provided. In Interactive Mode, users can browse their filesystem and toggle configuration settings within a Terminal User Interface (TUI). Sources: src/main.rs:60-140, README.md:65-95
CLI Argument Structure
The application defines its command-line interface using the Cli struct. This structure handles log file paths, parsing rules (regex), display limits, and the enabling of specialized analysis modules.
Core Configuration Flags
| Option | Short/Long | Type | Default Value | Description |
|---|---|---|---|---|
| File | [FILE] | PathBuf | None | Path to the log file. If omitted, triggers interactive mode. |
| Count | -c, --count | isize | 0 | Lines to read (0=tail, -1=all). |
| Regex | -r, --regex | String | Nginx Default | Pattern or file path for log parsing. |
| Date Format | -d, --date-format | String | %d/%b/%Y:%H:%M:%S %z | Format for parsing log timestamps. |
| Top | -t, --top | usize | 10 | Number of top entries to display. |
Sources: src/main.rs:64-94, README.md:234-250
Module Activation Flags
LogUtil uses boolean flags to toggle specific analysis tabs within the TUI. By default, only core tabs (Overview, Requests, Detailed) are enabled.
--enable-security: Enables the Security threat detection tab.--enable-performance: Enables response time and RPS monitoring.--enable-errors: Enables HTTP error code analysis (4xx/5xx).--enable-bots: Enables crawler and bot detection.--enable-sparkline: Enables real-time request trend visualization.--enable-heatmap: Enables hourly traffic pattern visualization.
Sources: src/main.rs:109-130, README.md:251-257, src/app.rs:56-82
Execution Flow Logic
The application logic determines how to proceed based on the presence of the file argument. If a file is provided, the CLI validates its existence and proceeds to analysis. If not, it enters a TUI-based selection mode.
Interactive Configuration (FileSettings)
When logutil starts without a file, the FileSettings system takes control. This module manages two distinct panels: a directory navigator and a settings editor.
File Selector & Settings State
The FileSettings struct tracks the current directory, available files, and the user's current configuration selections. It supports keyboard and mouse interaction to modify parameters before the analysis engine starts.
Sources: src/file_settings.rs:46-135
Interactive Input Actions
The system maps TUI interactions to a FileSettingsAction enum, which dictates whether the application should transition to the main analysis loop or shut down.
- StartAnalysis(CliArgs): Triggered by pressing Enter on a file or the "Start Analysis" button. It converts the TUI state back into a
CliArgsstructure for therun_analysis_with_argsfunction. - Exit: Triggered by
EscorCtrl+C, cleaning up the terminal raw mode before closing.
Sources: src/file_settings.rs:887-891, src/main.rs:207-235
Console Output Mode
Users can bypass the TUI entirely for quick reporting using the --show-urls and --show-ips flags. When these are active, the application processes the log file and prints a formatted summary to stdout before exiting.
// Logic from src/main.rs:293-331
if cli_args.show_urls || cli_args.show_ips {
let db = &*crate::memory_db::GLOBAL_DB;
let top_ips = db.get_top_ips(cli_args.top);
let top_urls = db.get_top_urls(cli_args.top);
// ... prints formatted tables to console ...
return Ok(());
}
Sources: src/main.rs:293-331, README.md:175-185
Conclusion
The CLI Configuration & Flags system in LogUtil provides a flexible bridge between command-line automation and interactive user experience. By utilizing structopt for initial parsing and a custom TUI state machine for interactive adjustments, the tool ensures that users can precisely configure regex patterns, log counts, and active modules regardless of their preferred workflow.