wx-server/internal/logger/my_formatter.go

33 lines
633 B
Go

package logger
import (
"bytes"
"fmt"
"time"
"github.com/sirupsen/logrus"
)
type MyFormatter struct {
for_server bool
for_gorm bool
}
func (m *MyFormatter) Format(entry *logrus.Entry) ([]byte, error) {
var b *bytes.Buffer
if entry.Buffer != nil {
b = entry.Buffer
} else {
b = &bytes.Buffer{}
}
timestamp := entry.Time.Format(time.DateTime)
var line string
if m.for_gorm {
line = fmt.Sprintf("[GORM ] [%s] [%s] %s\r\n", timestamp, entry.Level, entry.Message)
} else {
line = fmt.Sprintf("[SERVER] [%s] [%s] %s\r\n", timestamp, entry.Level, entry.Message)
}
b.WriteString(line)
return b.Bytes(), nil
}