1
0
mirror of https://github.com/haiwen/seafile-server.git synced 2025-08-13 20:46:56 +00:00
seafile-server/notification-server/logger.go

38 lines
782 B
Go
Raw Normal View History

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
}