mirror of
https://github.com/haiwen/seafile-server.git
synced 2025-09-22 11:39:05 +00:00
Format notification server log and redirect stderr to log (#707)
* 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>
This commit is contained in:
@@ -1,18 +1,36 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
log "github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
const (
|
||||
timestampFormat = "2006/01/02 15:04:05 "
|
||||
timestampFormat = "[2006-01-02 15:04:05] "
|
||||
)
|
||||
|
||||
type LogFormatter struct{}
|
||||
|
||||
func (f *LogFormatter) Format(entry *log.Entry) ([]byte, error) {
|
||||
buf := make([]byte, 0, len(timestampFormat)+len(entry.Message)+1)
|
||||
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
|
||||
|
Reference in New Issue
Block a user