package main import ( "fmt" "strings" log "github.com/sirupsen/logrus" ) const ( timestampFormat = "[2006-01-02 15:04:05] " ) type LogFormatter struct{} func (f *LogFormatter) Format(entry *log.Entry) ([]byte, error) { levelStr := entry.Level.String() if levelStr == "fatal" { levelStr = "ERROR" } else { levelStr = strings.ToUpper(levelStr) } level := fmt.Sprintf("[%s] ", levelStr) appName := "" if logToStdout { appName = "[notification-server] " } buf := make([]byte, 0, len(appName)+len(timestampFormat)+len(level)+len(entry.Message)+1) if logToStdout { buf = append(buf, appName...) } buf = entry.Time.AppendFormat(buf, timestampFormat) buf = append(buf, level...) buf = append(buf, entry.Message...) buf = append(buf, '\n') return buf, nil }