Skip to content

Add JSON log output format for easier log processing#1609

Merged
Eugeny merged 3 commits intowarp-tech:mainfrom
mrmm:feature/json-logs-output
Dec 30, 2025
Merged

Add JSON log output format for easier log processing#1609
Eugeny merged 3 commits intowarp-tech:mainfrom
mrmm:feature/json-logs-output

Conversation

@mrmm
Copy link
Copy Markdown
Contributor

@mrmm mrmm commented Dec 12, 2025

Summary

This PR adds support for JSON-formatted log output, making it easier to integrate Warpgate with log aggregation systems (ELK, Splunk, Datadog, etc.) and automated log processing pipelines.

Logs can be switched to JSON format via configuration file or CLI flag.

Changes

Configuration

  • Added LogFormat enum with text (default) and json variants
  • Added log.format option in warpgate.yaml:
    log:
      format: json  # or "text" (default)

CLI

  • Added --log-format flag that overrides config:
    warpgate --log-format json run

Backend

  • New JsonConsoleLayer tracing subscriber layer in warpgate-core/src/logging/
  • Outputs NDJSON (newline-delimited JSON) to stdout
  • Collects span context fields for structured logging

JSON Output Format

Each log line is a valid JSON object:

{"timestamp":"2025-01-15T10:30:45.123Z","level":"info","target":"warpgate::server","message":"Server started","port":2222}

Fields:

Field Description
timestamp ISO 8601 format with milliseconds
level trace, debug, info, warn, error
target Rust module path (e.g., warpgate::server)
message Log message
... Additional span fields are flattened into the object

Tests

  • Added integration tests for both config and CLI-based JSON logging
  • Tests validate JSON structure, required fields, and format compliance

Files Changed

  • config-schema.json - Updated schema with LogFormat
  • warpgate-common/Cargo.toml - Added clap dependency
  • warpgate-common/src/config/mod.rs - LogFormat enum and config
  • warpgate-core/src/logging/json_console.rs - New JsonConsoleLayer
  • warpgate-core/src/logging/mod.rs - Module export
  • warpgate/src/logging.rs - Layer initialization
  • warpgate/src/main.rs - CLI argument
  • tests/test_json_logs.py - Integration tests

Testing

All 150 tests pass, including the 2 new JSON logging tests.

Add configurable log format (text/json) for easier log processing and
integration with log aggregation systems.

- Add LogFormat enum with Text (default) and Json variants
- Add log.format config option in warpgate.yaml
- Add --log-format CLI flag (overrides config)
- Add JsonConsoleLayer for NDJSON output to stdout
- Include timestamp, level, target, message, and span fields
- Add integration tests for both config and CLI options
@mrmm mrmm marked this pull request as ready for review December 13, 2025 09:50
@mrmm
Copy link
Copy Markdown
Contributor Author

mrmm commented Dec 13, 2025

Hello @Eugeny, Thanks for this cool project !

Can you please review this PR, it just introduces json logging format on the stdout for the logger!

Not sure why the build are failing TBH, I will try to fix it in my branch if there is not other work in progress regarding that 🙏

@Eugeny
Copy link
Copy Markdown
Member

Eugeny commented Dec 26, 2025

Thank you for the PR! CI passes now except the new test - please rewrite it to use the provided test utils - in CI, tests run a special instrumented build of warpgate to measure coverage - the start_wg fixture takes care of that automatically

Refactor test_json_logs.py to use the existing test infrastructure
instead of standalone utilities:

- Use ProcessManager and start_wg() from conftest.py
- Use wait_port() from util.py
- Use timeout fixture for configurable timeouts
- Use share_with pattern for proper stdout capture
- Remove duplicated alloc_port() and wait_port() functions

This ensures tests work correctly with the instrumented build
for coverage measurement in CI.
@mrmm
Copy link
Copy Markdown
Contributor Author

mrmm commented Dec 27, 2025

@Eugeny Test are now passing is there anything needed for this PR to be reviewed 🙏

@Eugeny Eugeny merged commit 550f3fa into warp-tech:main Dec 30, 2025
14 checks passed
@Eugeny
Copy link
Copy Markdown
Member

Eugeny commented Dec 30, 2025

Thanks!

@all-contributors please add @mrmm for code

@allcontributors
Copy link
Copy Markdown
Contributor

@Eugeny

I've put up a pull request to add @mrmm! 🎉

Eugeny pushed a commit that referenced this pull request Dec 31, 2025
Adds @mrmm as a contributor for code.

This was requested by Eugeny [in this
comment](#1609 (comment))

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
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.

2 participants