Skip to content

logging: Add journald encoder wrapper#7623

Open
steadytao wants to merge 1 commit intocaddyserver:masterfrom
steadytao:feat/journald-encoder-wrapper
Open

logging: Add journald encoder wrapper#7623
steadytao wants to merge 1 commit intocaddyserver:masterfrom
steadytao:feat/journald-encoder-wrapper

Conversation

@steadytao
Copy link
Copy Markdown
Contributor

@steadytao steadytao commented Apr 3, 2026

Implements the #7611 feature request as an explicit logging encoder wrapper.

Summary

This adds a new journald encoder that wraps another encoder and prepends the systemd/journald priority prefix (<N>) to each emitted log line.

Example:

log {
    format journald {
        wrap json
    }
}

Why this shape

The issue discussion converged on keeping this:

  • opt-in rather than environment-detected
  • at the encoder layer rather than the writer/output layer
  • as a wrapper around an existing encoder rather than a completely separate transport

That means the wrapped encoder still controls the actual log format (json, console, etc.), while journald only adds the priority prefix that journald understands for stdout/stderr log streams.

This encoder does not write directly to journald.

Behaviour

Priority mapping currently follows the standard journald/syslog severity levels:

  • debug -> <7>
  • info -> <6>
  • warn -> <4>
  • error -> <3>
  • dpanic / panic / fatal -> <2>

If no wrapped encoder is specified, it follows the same default behavior as the existing wrapper encoders:

  • default to json
  • switch to console for terminal output

Tests

Added:

  • unit tests for severity prefix mapping and encoded output
  • a Caddyfile adaptation test for format journald { wrap console }

EDIT

Updated to also suppress the wrapped encoder’s timestamp by default when using format journald.

That means:

  • wrap console no longer includes the in-line timestamp
  • wrap json no longer includes the ts field

The intent is to avoid duplicating timestamp information that journald / journalctl already provides separately. Should be mentioned explicitly.

Implements + should close #7611.

Assistance Disclosure

No AI was used.

@steadytao steadytao force-pushed the feat/journald-encoder-wrapper branch from 46401f3 to d9fa1a4 Compare April 3, 2026 11:01
@steffenbusch
Copy link
Copy Markdown
Contributor

I tested it with both json and console

        log journal_log {
                output stderr
                format journald {
                        wrap console
                }
        }

It looks much better in journalctl now:

image image

Can it be configured so that the timestamp from the log message is dropped to remove that redundancy, as it is already present in journalctl?

@steadytao
Copy link
Copy Markdown
Contributor Author

My plan will be to make the journald wrapper suppress the wrapped encoder’s timestamp by default, so:

  • wrap console no longer includes the in-line timestamp
  • wrap json no longer includes the ts field

I’ll take a look at the cleanest way to do that without making the wrapper too invasive.

@steadytao steadytao force-pushed the feat/journald-encoder-wrapper branch from 1fc6907 to ffb1b0d Compare April 3, 2026 12:33
@steadytao
Copy link
Copy Markdown
Contributor Author

The journald wrapper now suppresses the timestamp emitted by the wrapped encoder by default, so:

  • wrap console drops the in-line timestamp
  • wrap json drops the ts field

That keeps journald’s own timestamp as the one shown by journalctl instead of duplicating it inside the log payload. (expected behaviour when toggled to unify with how journald is expected to be used)

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.

Improve systemd/journald logging

2 participants