Prefix log lines with syslog priority for journalctl colourisation #85
No reviewers
Labels
No labels
Bug
BuildIssue
Claude-fixed
Enhancement
In Progress
Low priority
On Hold
Rejected
Security
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
keyop-go/nfq_forwarder!85
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "issue37_journalctl_colour"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #37.
See the issue comment for the full investigation - summary: every line written to stderr under systemd got the same blanket journal priority (no per-line signal on a plain byte stream), so journalctl could not distinguish an Info line from an Error one and colourised nothing.
internal/log/syslog_prefix.goprefixes each line with<N>(the syslog/kernel priority scale systemd'sSyslogLevelPrefixoption parses - already systemd's own default for a journal-captured service, now made explicit indocs/nfq_forwarder.service), mappingDebug->7,Info->6,Warn->4,Error->3,FatalLevel->2 (crit). Only applied when stderr is not a terminal - an interactive session keeps tint's own ANSI colours untouched.Verified end to end against a real journald (not just unit tests): piped a throwaway program's output through
systemd-cat --level-prefix=trueand confirmed viajournalctl --output=jsonthat each entry'sPRIORITYfield matches (7/6/4/3) with the prefix stripped from the message, and via the pager's raw ANSI escapes that journalctl renders ERROR in bold red, WARN in bold yellow, DEBUG dim grey, INFO plain.make lint/make testclean.Tested and this works as intended. Have also raised issue #86 as it wasn't clear from journalctl output when the version under test started, but that's not part of this MR.
Works well - approving.