Skip to content

Improve systemd/journald logging #7611

@otbutz

Description

@otbutz

Issue Details

Caddy simply writes to stdout/stderr by default. This is perfectly fine, but makes it rather cumbersome to filter events of a certain level using journalctl later on.

The good thing is that systemd interprets a custom level prefix by default: https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html#SyslogLevelPrefix=

Here you can find the list of levels: https://www.freedesktop.org/software/systemd/man/latest/sd-daemon.html

#define SD_EMERG   "<0>"  /* system is unusable */
#define SD_ALERT   "<1>"  /* action must be taken immediately */
#define SD_CRIT    "<2>"  /* critical conditions */
#define SD_ERR     "<3>"  /* error conditions */
#define SD_WARNING "<4>"  /* warning conditions */
#define SD_NOTICE  "<5>"  /* normal but significant condition */
#define SD_INFO    "<6>"  /* informational */
#define SD_DEBUG   "<7>"  /* debug-level messages */

e.g this line would be logged as a warning to journald with the <4> prefix getting stripped:

<4>{"level":"warn","ts":1775048791.656852,"logger":"http","msg":"HTTP/2 skipped because it requires TLS","network":"tcp","addr":":80"}

It would be nice if either caddy would output the prefix by default if executed via systemd or it could be enabled per configuration.

Assistance Disclosure

AI not used

If AI was used, describe the extent to which it was used.

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    discussion 💬The right solution needs to be foundfeature ⚙️New feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions