Skip to content

DroidOctopus/loganalyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Log Analyzer

This Rust project analyzes log files to provide insights into their content. It can perform the following tasks:

  • Count the total number of lines in a log file.
  • Count the occurrences of specific keywords within the log file.
  • Identify and extract IP addresses from the log file.

Project Structure

log-analyzer/
├── Cargo.lock
├── Cargo.toml
├── src/
│   └── main.rs
└── test_log.log
  • Cargo.lock: Auto-generated file that specifies the exact versions of dependencies used.
  • Cargo.toml: Project configuration file that defines dependencies.
  • src/main.rs: The main Rust source code file.
  • test_log.log: A sample log file for testing.

Features

  • Line Counting: Efficiently counts the total number of lines in a given log file.
  • Keyword Search: Allows you to specify keywords and counts their occurrences throughout the log file.
  • IP Address Extraction: Identifies and lists all IP addresses found within the log file.

Getting Started

Prerequisites

Building the Project

  1. Clone the repository:
bash
    git clone <repository-url>
    cd log-analyzer
    
  1. Build the project:
bash
    cargo build --release
    

Running the Project

  1. Run the following command:
bash
   cargo run --release <path-to-log-file> <keyword1> <keyword2> ...
   

The program will print:

  • The total number of lines
  • The number of occurrences of the keywords
  • A list of the ip addresses

For example, to analyze test_log.log for the keywords "error" and "warning":

bash
   cargo run --release test_log.log error warning
   

Example Usage

Assume test_log.log contains the following:

2023-10-27 00:00:00 INFO: System started. IP: 192.168.1.1
2023-10-27 00:00:05 WARNING: Low disk space. IP: 10.0.0.1
2023-10-27 00:00:10 ERROR: Failed to connect. IP: 8.8.8.8
2023-10-27 00:00:15 INFO: System is running.
2023-10-27 00:00:20 ERROR: File not found. IP: 172.16.0.1

Running:

bash
cargo run --release test_log.log error warning

Will output:

Total lines: 5
Occurrences of 'error': 2
Occurrences of 'warning': 1
IP Addresses found: ["192.168.1.1", "10.0.0.1", "8.8.8.8", "172.16.0.1"]

Contributing

Contributions are welcome! Please feel free to submit pull requests or open issues.

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages