29 lines
542 B
Go
29 lines
542 B
Go
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
|
|
}
|