From 92f9b8f891ed758d6d56278a9c2418006f9117e9 Mon Sep 17 00:00:00 2001 From: Justin Reagor Date: Fri, 2 Feb 2018 13:22:27 -0500 Subject: [PATCH] logging: Add job name and PID to default log output lines --- config/logger/logging.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/config/logger/logging.go b/config/logger/logging.go index 8c0c6aa2..d593cc6c 100644 --- a/config/logger/logging.go +++ b/config/logger/logging.go @@ -97,7 +97,18 @@ type DefaultLogFormatter struct { func (f *DefaultLogFormatter) Format(entry *logrus.Entry) ([]byte, error) { b := &bytes.Buffer{} logger := log.New(b, "", 0) - logger.Println(time.Now().Format(f.TimestampFormat) + " " + string(entry.Message)) + + fields := "" + if len(entry.Data) != 0 { + if jobName := entry.Data["job"]; jobName != nil { + fields = fmt.Sprintf("%s %s", fields, jobName) + } + if pidID := entry.Data["pid"]; pidID != nil { + fields = fmt.Sprintf("%s %d", fields, pidID) + } + } + + logger.Println(time.Now().Format(f.TimestampFormat) + fields + " " + string(entry.Message)) // Panic and Fatal are handled by logrus automatically return b.Bytes(), nil }