mirror of
https://github.com/haiwen/seafile-server.git
synced 2025-08-18 06:48:03 +00:00
* Format notification server log and redirect stderr to log * Set http server error log * Delete unused file * Modify pkg name --------- Co-authored-by: 杨赫然 <heran.yang@seafile.com>
38 lines
782 B
Go
38 lines
782 B
Go
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
|
|
}
|