| Crates.io | time-parser |
| lib.rs | time-parser |
| version | 0.1.0 |
| created_at | 2025-11-20 10:28:55.680881+00 |
| updated_at | 2025-11-20 10:28:55.680881+00 |
| description | A simple hand-written parser for time log entries. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1941770 |
| size | 28,916 |
time-parser is a Rust command-line tool and library for parsing timestamped log lines.
It automatically detects multiple timestamp formats and converts logs into structured data.
This project was created as a parsing assignment and demonstrates:
thiserror and anyhowThe parser automatically detects and supports three formats:
| ISO | 2024-03-15 12:00:00 |
| European | 15-03-2024 12:00:00 |
| American | 03-15-2024 12:00:00 |
YYYY-MM-DD)DD-MM-YYYY)MM-DD-YYYY)Each log line must follow this structure:
TIMESTAMP [KIND] MESSAGE METADATA
makefile Copy code
Example:
15-03-2024 10:00:00 [INFO] Server started user=alice id=42
yaml Copy code
Formal grammar (EBNF-style):
LOG = TIMESTAMP " [" KIND "] " MESSAGE (" " METADATA)? TIMESTAMP = ISO | EU | US ISO = YYYY "-" MM "-" DD " " HH ":" MM ":" SS EU = DD "-" MM "-" YYYY " " HH ":" MM ":" SS US = MM "-" DD "-" YYYY " " HH ":" MM ":" SS
KIND = uppercase_text MESSAGE = text until metadata starts METADATA = KVPAIR ( " " KVPAIR )* KVPAIR = KEY "=" VALUE
markdown Copy code
Timestamp parser
chrono::NaiveDateTimeKind parser
[INFO], [WARN], [ERROR] etc.Message parser
key=value token appearsMetadata parser
HashMap<String, String>Final output Each line becomes this Rust struct:
pub struct Entry {
pub timestamp: NaiveDateTime,
pub kind: String,
pub message: String,
pub metadata: HashMap<String, String>,
}
💻 CLI Usage
Parse a file:
bash
Copy code
time-parser parse logs.txt
Show credits:
bash
Copy code
time-parser credits
Show help:
bash
Copy code
time-parser --help
Output example:
json
Copy code
{
"timestamp": "2024-03-15 10:00:00",
"kind": "INFO",
"message": "Server started",
"metadata": {
"user": "alice",
"id": "42"
}
}