Log Parser is a simple Rust-based log file parser that uses pest
crate to parse log files, helping with extracting datetime, log levels and messages.
Log Parser can be used to extract logs with specified log level
into another file OR/AND into json
format using serde
.
Logs are parsed in the following format: Datetime Level Message
.
- Datetime constists of
date
andtime
:- Date - date specified in
YYYY-MM-DD
format, e.g.2024-11-07
. - Time - time specified in
HH:MM:SS
format, e.g.15:41:07
.
- Date - date specified in
- Level - one of three (currently) logging levels:
INFO
,WARNING
,ERROR
. - Message - message of the log line.
Log parser can be used via CLI (created using clap
) with the following options:
log_parser_kma parse -f <file_path> -o <output_path> [options]
-f, --file <file_path>
- specifies the path to the log file to be parsed. (Required)-o, --output <output_path>
- specifies the path to the output file. (Required)-l, --level <log_level>
- specifies log level to filter by (INFO
,WARNING
orERROR
). (Optional)-j, --to-json
- outputs the logs in JSON format instead of plain text. (Optional)
Parse a log file and save output as JSON
log_parser_kma parse -f logs.log -o results.txt -j
Parse a log file, filter ERROR
level logs and output as JSON
log_parser_kma parse -f newlogs.log -o errorlogs.txt -l ERROR -j
log_parser_kma help
log_parser_kma credits