Skip to content

fix: add independent log parser fixtures and fix nginx parser ordering (Closes #5)#67

Open
jacksong2049-prog wants to merge 1 commit into
weilixiong:mainfrom
jacksong2049-prog:fix/parser-fixtures-5
Open

fix: add independent log parser fixtures and fix nginx parser ordering (Closes #5)#67
jacksong2049-prog wants to merge 1 commit into
weilixiong:mainfrom
jacksong2049-prog:fix/parser-fixtures-5

Conversation

@jacksong2049-prog

Copy link
Copy Markdown

Summary

Add independent hand-written log parser fixtures and fix a parser ordering bug where NginxLogParser was never reached because TextLogParser matches all non-empty lines first.

Changes

New files

  • tests/__init__.py — test package init
  • tests/test_log_aggregator_fixtures.py — 13 test cases across 5 test classes

Modified files

  • tools/log_aggregator.py — fix parser ordering: NginxLogParser now runs before TextLogParser

Fixtures (all hand-written, NOT parser-generated)

JSON (4 fixtures): standard structured log, severity/logger alternates, @timestamp/lvl alternates, minimal message-only log

Text (5 fixtures): syslog-style, Python logging, INFO/DEBUG levels, FATAL without timestamp

Nginx (3 fixtures): 200 OK, 500 server error, 404 not found — all with full combined log format fields

Malformed (8 cases): empty lines, invalid JSON, binary garbage, long whitespace — all verified to not crash

Bug fix

The parser list was [JSON, Text, Nginx]. Since TextLogParser.parse() returns a dict for ANY non-empty line, NginxLogParser was never reachable. The fix reorders to [JSON, Nginx, Text] so:

  1. JSON lines → JSONLogParser
  2. Nginx access logs → NginxLogParser
  3. Everything else → TextLogParser

Testing

python3 -m unittest tests/test_log_aggregator_fixtures.py -v

All 13 tests pass, covering:

  • JSONLogParser (6 tests)
  • TextLogParser (6 tests)
  • NginxLogParser (4 tests)
  • Malformed input handling (1 parameterized test over 8 cases)
  • Aggregator integration (4 tests: format routing, level counts, error timeline, JSON export)

Checklist

  • Independent fixtures are hand-written, not parser-generated
  • JSON, text, and nginx formats all covered
  • Malformed/unsupported lines handled without crashes
  • Existing CLI behavior preserved (only parser ordering changed to fix unreachable parser)
  • No unrelated changes

Closes #5

- Add independent hand-written fixtures for JSON, text, and nginx log formats
- Add focused parser validation tests (12 test cases)
- Fix parser ordering: NginxLogParser now runs before TextLogParser to prevent nginx lines from being swallowed by the generic text parser
- Add malformed/edge-case line handling validation
- All fixtures are hand-written, not parser-generated — eliminating false-pass risk

Closes weilixiong#5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[$25 BOUNTY] [Python] Add independent log parser fixtures

1 participant