Skip to content

enigma-137/log-analyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Log Analyzer

A high-performance Rust CLI tool for parsing and analyzing server log files (Nginx, Apache, and custom formats). It provides statistical insights, error extraction, anomaly detection, and export capabilities to JSON or CSV.

Features

  • Multi-format Support: Parse Nginx, Apache, and custom log formats using regex patterns
  • Parallel Processing: Utilizes Rayon for fast, parallel log parsing with progress indicators
  • Comprehensive Analysis:
    • Request statistics (total requests, error rates, average response sizes)
    • Error extraction and summarization
    • Anomaly detection based on patterns
  • Export Options: Export analysis reports to JSON or CSV formats
  • CLI Interface: Simple command-line interface with Clap

Installation

From Source

Ensure you have Rust installed (edition 2021 or later). Then:

git clone <repository-url>
cd log-analyzer
cargo build --release

The binary will be available at target/release/log-analyzer.

Using Cargo

cargo install --git <repository-url> log-analyzer

Usage

Basic Analysis

Analyze a log file with default settings (Nginx format, JSON export):

log-analyzer analyze --file /path/to/access.log

Specify Format

For Apache logs:

log-analyzer analyze --file /path/to/access.log --format apache

For custom format:

log-analyzer analyze --file /path/to/custom.log --format custom

Export Results

Export to CSV:

log-analyzer analyze --file /path/to/access.log --output report.csv --export-format csv

Export to JSON:

log-analyzer analyze --file /path/to/access.log --output report.json --export-format json

Error-Only Analysis

Focus on error entries only:

log-analyzer analyze --file /path/to/access.log --errors-only

Full Example

log-analyzer analyze \
  --file /var/log/nginx/access.log \
  --format nginx \
  --output analysis.json \
  --export-format json \
  --errors-only

The tool will output a summary table to stdout and optionally save detailed results to the specified file.

Output Format

The analysis report includes:

  • Statistics: Total requests, error count and rate, average response size
  • Errors: Summarized error information
  • Anomalies: Detected unusual patterns in the logs

Contributing

We welcome contributions! Please follow these guidelines:

Development Setup

  1. Clone the repository:

    git clone <repository-url>
    cd log-analyzer
  2. Build the project:

    cargo build
  3. Run tests:

    cargo test
  4. Run benchmarks:

    cargo bench

Code Style

  • Follow Rust standard formatting: cargo fmt
  • Run clippy for linting: cargo clippy
  • Ensure all tests pass before submitting

Adding Features

  1. Create a feature branch: git checkout -b feature/your-feature
  2. Implement your changes
  3. Add tests for new functionality
  4. Update documentation if needed
  5. Submit a pull request

Reporting Issues

  • Use GitHub issues for bug reports and feature requests
  • Include log samples and error messages when reporting bugs
  • Specify your Rust version and OS

License

This project is licensed under the MIT License. See LICENSE file for details.

Dependencies

  • clap: Command-line argument parsing
  • regex: Regular expression matching
  • serde & serde_json: Serialization
  • csv: CSV export
  • chrono: Date/time handling
  • anyhow & thiserror: Error handling
  • rayon: Parallel processing
  • indicatif: Progress bars

About

A Rust-based CLI tool for analyzing server logs, supporting formats like Nginx, Apache, and custom regex-based parsing. It features parallel processing, statistical analysis (requests, errors, response sizes), error extraction, anomaly detection, and export to JSON/CSV.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages