init: first steps
This commit is contained in:
28
modules/log/formatter.go
Normal file
28
modules/log/formatter.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type TextFormatter struct {
|
||||
logrusFormatter logrus.TextFormatter
|
||||
prefix []byte
|
||||
}
|
||||
|
||||
func NewTextFormatter(prefix string) *TextFormatter {
|
||||
return &TextFormatter{
|
||||
logrusFormatter: logrus.TextFormatter{},
|
||||
prefix: []byte(fmt.Sprintf("[%s] ", prefix)),
|
||||
}
|
||||
}
|
||||
|
||||
func (t *TextFormatter) Format(item *logrus.Entry) ([]byte, error) {
|
||||
original, err := t.logrusFormatter.Format(item)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return append(t.prefix, original...), nil
|
||||
}
|
||||
Reference in New Issue
Block a user