Skip to content

Commit

Permalink
logging: Add job name and PID to default log output lines
Browse files Browse the repository at this point in the history
  • Loading branch information
Justin Reagor committed Feb 22, 2018
1 parent a988b75 commit 92f9b8f
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion config/logger/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 92f9b8f

Please sign in to comment.