X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/f5c601f1801aaa276f8c335fcb51c373edc0b50c..42b4acd4ba70d3c12da4513d139717e592eefe4a:/daemon_log.go?ds=inline diff --git a/daemon_log.go b/daemon_log.go index f1e4b0b..1ff6aa4 100644 --- a/daemon_log.go +++ b/daemon_log.go @@ -104,18 +104,6 @@ func (h *DaemonLogHandler) WithGroup(name string) slog.Handler { return &clone } -// daemonLogger returns a logger for one daemon part. JOURNAL_STREAM selects -// syslog priorities without a time stamp. Other output carries the standard -// time stamp and level. -func daemonLogger(out io.Writer, prefix string) *slog.Logger { - return slog.New(&DaemonLogHandler{ - out: out, - prefix: prefix, - journal: os.Getenv("JOURNAL_STREAM") != "", - mutex: &sync.Mutex{}, - }) -} - // daemonLogAttr resolves and writes one attribute, or keeps its cause for the // end of the line. Groups flatten into dotted keys and empty attributes produce // no text. @@ -150,18 +138,30 @@ func daemonLogAttr(line *strings.Builder, group string, attr slog.Attr, cause *s line.WriteByte('=') if attr.Value.Kind() == slog.KindDuration { - line.WriteString(durationText(attr.Value.Duration())) + line.WriteString(daemonLogDuration(attr.Value.Duration())) } else { fmt.Fprint(line, attr.Value.Any()) } } -// durationText returns d for a log line: rounded to the second, or to the +// daemonLogDuration returns d for a log line: rounded to the second, or to the // millisecond when it is shorter than a second. -func durationText(d time.Duration) string { +func daemonLogDuration(d time.Duration) string { if d < time.Second { return d.Round(time.Millisecond).String() } return d.Round(time.Second).String() } + +// daemonLogger returns a logger for one daemon part. JOURNAL_STREAM selects +// syslog priorities without a time stamp. Other output carries the standard +// time stamp and level. +func daemonLogger(out io.Writer, prefix string) *slog.Logger { + return slog.New(&DaemonLogHandler{ + out: out, + prefix: prefix, + journal: os.Getenv("JOURNAL_STREAM") != "", + mutex: &sync.Mutex{}, + }) +}