github.com/dfklegend/cell2/utils@v0.0.0-20240402033734-a0a9f3d9335d/logger/proxy/simple_log_format.go (about) 1 package proxy 2 3 import ( 4 "bytes" 5 "fmt" 6 7 "github.com/sirupsen/logrus" 8 ) 9 10 type simpleLogFormat struct { 11 Name string 12 TimestampFormat string 13 } 14 15 func (s *simpleLogFormat) Format(entry *logrus.Entry) ([]byte, error) { 16 var b *bytes.Buffer 17 if entry.Buffer != nil { 18 b = entry.Buffer 19 } else { 20 b = &bytes.Buffer{} 21 } 22 23 b.WriteString(entry.Time.Format(s.TimestampFormat)) 24 b.WriteString(fmt.Sprintf("[%s]", entry.Level.String())) 25 b.WriteString(fmt.Sprintf("[%s]", s.Name)) 26 b.WriteString(fmt.Sprintf("%s", entry.Message)) 27 b.WriteByte('\n') 28 return b.Bytes(), nil 29 } 30 31 func NewSimpleLogFormat(name string) *simpleLogFormat { 32 return &simpleLogFormat{ 33 Name: name, 34 TimestampFormat: "[2006-01-02 15:04:05.000]", 35 } 36 }