feat(log): implement structured logging with rotation #105

Merged
fuzzy merged 3 commits from feature/0051-implement-logging into main 2026-07-05 14:47:33 +00:00
Owner

What

Implement a comprehensive logging system: JSON structured logging, configurable log levels, rotating file handler, and CLI integration.

Why

Production-ready logging for debugging, monitoring, and log management.

Testing

  • 112 unit tests pass (10 new for logging)
  • Pre-commit hooks pass (ruff + mypy strict)
  • Coverage: 90%

Breaking Changes

None.

Notes

New config fields: json_logs, log_max_bytes, log_backup_count. New src/kronai/log.py module with JSONFormatter and setup_logging().

Closes #0048
Closes #0049
Closes #0050
Closes #0051

## What Implement a comprehensive logging system: JSON structured logging, configurable log levels, rotating file handler, and CLI integration. ## Why Production-ready logging for debugging, monitoring, and log management. ## Testing - [x] 112 unit tests pass (10 new for logging) - [x] Pre-commit hooks pass (ruff + mypy strict) - [x] Coverage: 90% ## Breaking Changes None. ## Notes New config fields: `json_logs`, `log_max_bytes`, `log_backup_count`. New `src/kronai/log.py` module with `JSONFormatter` and `setup_logging()`. Closes #0048 Closes #0049 Closes #0050 Closes #0051
- JSONFormatter for structured log output
- setup_logging with console + rotating file handler
- Configurable log level, JSON toggle, rotation params
- Integrated into CLI main entry point
Closes #0048
Closes #0049
Closes #0050
Closes #0051
Cover JSONFormatter, setup_logging with level, console/file
handlers, JSON output, handler cleanup, and rotation config.
docs: mark Phase 4 Task 1 complete
All checks were successful
CI / test (pull_request) Successful in 50s
CI / lint (pull_request) Successful in 1m15s
f12e5e24b0
Logging system with structured JSON output, log levels,
and rotation done.
Closes #0051
the.auditor left a comment

Automated Review — PR #105

Result: APPROVED


Clean logging implementation. JSON formatter, rotating file handler, configurable levels, and CLI integration all work well.

  • Correctness: JSONFormatter correctly serializes log records (timestamp, level, logger, message, exception). setup_logging configures console + file handlers, clears stale handlers on reconfig. Rotating file handler with configurable sizes.
  • Completeness: Closes #48–#51. ROADMAP updated. Config model updated with new fields. Example config updated.
  • Test coverage: 10 tests covering JSON formatter (basic + exception), logging setup (level, invalid level, console handler, file handler, handler clearing, rotation config), and JSON output validation.
  • Error handling: Invalid log level defaults to INFO. setup_logging is defensive.
  • Maintainability: Clean 78-line module. JSONFormatter extends logging.Formatter as expected.

Suggestions (non-blocking)

  1. src/kronai/cli.py:113-115main() calls load_config() to get log settings, then subcommands (_cmd_list, _cmd_run) call it again. Config is loaded twice every command. Consider passing the loaded config to subcommands.

  2. src/kronai/log.py:32 — JSON timestamp format %Y-%m-%dT%H:%M:%S lacks timezone info. Consider using UTC (time.gmtime) and appending Z for unambiguous timestamps.

  3. tests/unit/test_log.py:85-97test_json_format_produces_valid_json manually clears root handlers and adds a StringIO handler. This is fragile — if run after other setup_logging tests, state leakage could occur. Consider using pytest's caplog fixture or isolating via a logger hierarchy (child loggers) instead of the root.

## Automated Review — PR #105 **Result: APPROVED** --- Clean logging implementation. JSON formatter, rotating file handler, configurable levels, and CLI integration all work well. - **Correctness**: `JSONFormatter` correctly serializes log records (timestamp, level, logger, message, exception). `setup_logging` configures console + file handlers, clears stale handlers on reconfig. Rotating file handler with configurable sizes. - **Completeness**: Closes #48–#51. ROADMAP updated. Config model updated with new fields. Example config updated. - **Test coverage**: 10 tests covering JSON formatter (basic + exception), logging setup (level, invalid level, console handler, file handler, handler clearing, rotation config), and JSON output validation. - **Error handling**: Invalid log level defaults to INFO. `setup_logging` is defensive. - **Maintainability**: Clean 78-line module. `JSONFormatter` extends `logging.Formatter` as expected. ### Suggestions (non-blocking) 1. **`src/kronai/cli.py:113-115`** — `main()` calls `load_config()` to get log settings, then subcommands (`_cmd_list`, `_cmd_run`) call it again. Config is loaded twice every command. Consider passing the loaded config to subcommands. 2. **`src/kronai/log.py:32`** — JSON timestamp format `%Y-%m-%dT%H:%M:%S` lacks timezone info. Consider using UTC (`time.gmtime`) and appending `Z` for unambiguous timestamps. 3. **`tests/unit/test_log.py:85-97`** — `test_json_format_produces_valid_json` manually clears root handlers and adds a StringIO handler. This is fragile — if run after other `setup_logging` tests, state leakage could occur. Consider using pytest's `caplog` fixture or isolating via a logger hierarchy (child loggers) instead of the root.
fuzzy merged commit f12e5e24b0 into main 2026-07-05 14:47:33 +00:00
fuzzy deleted branch feature/0051-implement-logging 2026-07-05 14:47:33 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
thwap/kronai!105
No description provided.