Crates.io | log_parser_by_syn1ak |
lib.rs | log_parser_by_syn1ak |
version | 0.3.0 |
source | src |
created_at | 2024-11-13 11:34:22.788154 |
updated_at | 2024-11-13 11:46:47.926441 |
description | A parser for analyzing structured log files, utilizing the Pest parsing library. `log_parser` extracts components such as date, time, log level, module, request ID, error code, and message from each log entry. This enables efficient log analysis, filtering, and reporting, facilitating troubleshooting and monitoring in complex systems. |
homepage | |
repository | https://github.com/Syn1ak/log_parser_by_syn1ak.git |
max_upload_size | |
id | 1446419 |
size | 29,734 |
log_parser_by_syn1ak
is a Rust project designed to parse structured log files. It is built using the Pest parsing library, which enables the extraction of specific components from log entries, such as date, time, log level, and message content.
The parser works by defining each component of a log entry through distinct grammar rules in Pest, allowing it to identify and extract specific parts of a log. This design enables you to capture structured data from log files, which can be used in log analysis pipelines, monitoring systems, and debugging processes.
Each log entry has the following structure:
log_entry = { date ~ " " ~ time ~ " " ~ level ~ " " ~ (module ~ " ")? ~ (request_id ~ " ")? ~ (error_code ~ " ")? ~ message }
YYYY-MM-DD
format.HH:MM:SS
format, optionally followed by a three-letter timezone (e.g., UTC
).INFO
, WARN
, ERROR
, DEBUG
).mod-
, representing the module or subsystem generating the log.req-
, allowing tracking of requests or processes.Here’s a breakdown of each grammar rule used in log_parser_by_syn1ak
:
year = { ASCII_DIGIT{4} }
month = { "0" ~ ASCII_DIGIT | "1" ~ '0'..'2' }
day = { "0" ~ ASCII_DIGIT | '1'..'2' ~ ASCII_DIGIT | "3" ~ '0'..'1' }
date = { year ~ "-" ~ month ~ "-" ~ day }
time = { ASCII_DIGIT{2} ~ ":" ~ ASCII_DIGIT{2} ~ ":" ~ ASCII_DIGIT{2} ~ (ASCII_ALPHA{3})? }
level = { "INFO" | "WARN" | "ERROR" | "DEBUG" | "TRACE" | "FATAL" }
module = { "mod-" ~ ASCII_ALPHA+ }
request_id = { "req-" ~ ASCII_ALPHANUMERIC+ }
error_code = { ASCII_DIGIT{3,5} }
message = { (!"\n" ~ ANY)+ }
An example log entry that follows this structure might look like:
2024-11-06 12:00:00UTC INFO mod-network req-12345 404 System started successfully
By parsing logs in this structured way, applications can perform detailed log analysis and visualization, improving error tracking and debugging processes.
Parsing a Log File: To parse a log file, specify the file path:
cargo run -- <file_path>
or
make run FILE=<file_path>
Display Credits:
Use the credits
subcommand to display project information:
cargo run -- credits
or
make credits
Run Tests: To test the parser and verify the grammar rules, run:
cargo test
or
make test