Skip to content

Allow for journald logs filtering on a per-unit basis - #24058

Merged
yuwata merged 6 commits into
systemd:mainfrom
qdeslandes:journald_regex_filtering
Dec 15, 2022
Merged

yuwata merged 6 commits into
systemd:mainfrom
qdeslandes:journald_regex_filtering

Conversation

@qdeslandes

@qdeslandes qdeslandes commented Jul 18, 2022 •

Copy link
Copy Markdown
Contributor

Implement mechanism to filter logs ingested by journald using regexes (#6432).

Implement for two new keywords in unit files (in Service section):

  • LogIncludeRegex=
  • LogExcludeRegex=

When journald will process logs on a unit with LogIncludeRegex defined, it will continue processing if the log message matches the regex, and discard it if it doesn't. The opposite behaviour is used for LogExcludeRegex. If none is defined, then all log messages are processed as usual. If both are defined, then the log message must match LogIncludeRegex but not LogExcludeRegex to be processed.

flowchart TD
    A{{Is LogIncludeRegex defined?}}
    B{{Does LogIncludeRegex matches?}}
    C{{Is LogExcludeRegex defined?}}
    D{{Does LogExcludeRegex matches?}}
    F>Discard log]
    E>Ingest log]

    style A fill:#f5f3f4,stroke:#219ebc,stroke-width:3px
    style B fill:#f5f3f4,stroke:#219ebc,stroke-width:3px
    style C fill:#f5f3f4,stroke:#219ebc,stroke-width:3px
    style D fill:#f5f3f4,stroke:#219ebc,stroke-width:3px
    style E fill:#f5f3f4,stroke:#219ebc,stroke-width:3px
    style F fill:#f5f3f4,stroke:#219ebc,stroke-width:3px


    A -- YES --> B -- YES --> C -- YES --> D
    A -- NO --> C
    B -- NO --> F
    C -- NO --> E
    D -- NO --> E
    D -- YES --> F
Loading

Both regexes are read from the unit file (or from D-Bus or systemctl set-property) and stored within the unit's cgroup xattr for journald to read.

Changes in this PR have been tested using mkosi qemu. Sending logs to journald using logger, systemd-cat and StandardOutput=journal. This change is feature complete, I will add a last commit to update integration tests.

Based on #25394

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.