mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-16 15:02:43 +00:00
log: journald integration (#2869)
Provide a bit more journald integration. Specifically: - support emission of printk-style log level prefixes, documented in [`sd-daemon`(3)](https://man7.org/linux/man-pages/man3/sd-daemon.3.html#DESCRIPTION), that allow journald to automatically annotate stderr log lines with their level; - add a new "journaldflags" item that is supposed to be used in place of "stdflags" when under journald to reduce log clutter (i. e. strip date/time info to avoid duplication, and use log level prefixes instead of textual log levels); - detect whether stderr and/or stdout are attached to journald by parsing `$JOURNAL_STREAM` environment variable and adjust console logger defaults accordingly. <!--start release-notes-assistant--> ## Draft release notes <!--URL:https://codeberg.org/forgejo/forgejo--> - Features - [PR](https://codeberg.org/forgejo/forgejo/pulls/2869): <!--number 2869 --><!--line 0 --><!--description bG9nOiBqb3VybmFsZCBpbnRlZ3JhdGlvbg==-->log: journald integration<!--description--> <!--end release-notes-assistant--> Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2869 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: Ivan Shapovalov <intelfx@intelfx.name> Co-committed-by: Ivan Shapovalov <intelfx@intelfx.name>
This commit is contained in:
parent
a72763f5a3
commit
012a1e0497
9 changed files with 169 additions and 18 deletions
|
@ -90,9 +90,17 @@ func colorSprintf(colorize bool, format string, args ...any) string {
|
|||
// EventFormatTextMessage makes the log message for a writer with its mode. This function is a copy of the original package
|
||||
func EventFormatTextMessage(mode *WriterMode, event *Event, msgFormat string, msgArgs ...any) []byte {
|
||||
buf := make([]byte, 0, 1024)
|
||||
buf = append(buf, mode.Prefix...)
|
||||
t := event.Time
|
||||
flags := mode.Flags.Bits()
|
||||
|
||||
// if log level prefixes are enabled, the message must begin with the prefix, see sd_daemon(3)
|
||||
// "A line that is not prefixed will be logged at the default log level SD_INFO"
|
||||
if flags&Llevelprefix != 0 {
|
||||
prefix := event.Level.JournalPrefix()
|
||||
buf = append(buf, prefix...)
|
||||
}
|
||||
|
||||
buf = append(buf, mode.Prefix...)
|
||||
if flags&(Ldate|Ltime|Lmicroseconds) != 0 {
|
||||
if mode.Colorize {
|
||||
buf = append(buf, fgCyanBytes...)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue