Help us measure site usage?

With your permission, we use self-hosted analytics to understand page usage. It is optional and does not affect the Service. Learn more.

C++intermediatedevopsAI generated

Multi-Format Log Parser & Aggregator

Build a C++ command-line tool that reads log files in several formats (plain text, syslog, and JSON lines, where each line is a JSON object) and turns them all into one common form, so you can search and summarize logs from different programs together. You can filter by time range, minimum severity and source, and get summaries such as the number of errors per service. Each format has its own parser behind a shared interface, so adding a new format means adding one class. You'll learn designing interfaces with abstract classes, std::regex, parsing JSON with nlohmann/json, working with dates using std::chrono, command-line options, and unit testing.

Estimate
~10.5h
Steps
6
Completed by
0
Proposed by
codeseed.app

std::regex · nlohmann/json

Project roadmap

  1. 01

    Define the common log entry

    ~1.5h

    Set up a CMake project, adding nlohmann/json (for example with FetchContent). Define a LogEntry struct with a timestamp (std::chrono::system_clock::time_point), a severity enum (debug, info, warning, error, critical), a source and a message. Define an abstract Parser class with a method that takes a line and returns std::optional<LogEntry>. Write sample log files for each format. Done when: the project builds, and the sample files exist.

  2. 02

    Parse plain text and syslog

    ~2.5h

    Implement PlainParser for lines such as 2026-03-15 10:22:01 ERROR payments: timeout, and SyslogParser for the classic syslog format (Mar 15 10:22:01 host app[123]: message), using std::regex. Map each format's severity words to the enum. Syslog lines don't include the year, so take it from an option or the current year. Return std::nullopt for lines that don't match. Done when: unit tests parse the sample lines correctly.

  3. 03

    Parse JSON lines

    ~1.5h

    Implement JsonParser with nlohmann/json: read the time, level, service and message fields (with the field names configurable), and handle invalid JSON and missing fields by returning std::nullopt instead of throwing. Choose the parser with --format, or detect it from the first lines. Done when: JSON lines, including broken ones, are handled correctly.

  4. 04

    Filter entries

    ~1.5h

    Add options: --since and --until (ISO dates), --min-severity and --source (can be repeated). Read files given as arguments, or standard input, line by line. Print matching entries in one uniform format, and count skipped lines per file, printed to stderr at the end. Done when: filtering by time and severity returns exactly the expected lines from the samples.

  5. 05

    Summarize

    ~1.5h

    Add --summary, which prints tables of entries per severity, per source, and errors per source per hour, aligned in columns. Add --json to print the summary as JSON using nlohmann/json. Done when: the summary counts match the sample files.

  6. 06

    Test it

    ~2h

    Write unit tests with GoogleTest or Catch2 for each parser (valid, broken, edge cases such as empty messages and unusual severity words), the filters, and the summary counts, plus a test that mixes files in different formats. Done when: ctest passes.

Ready to build this?

Get a GitHub repo and start building. Your AI reviewer checks each step as you go.

~10.5h · 6 steps

Tech stack

std::regexnlohmann/json