mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-24 03:47:45 +08:00
refactor(eventlog) use polite formatter as a direct dependency
License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
This commit is contained in:
parent
884d629a56
commit
ddb0189b90
@ -17,7 +17,7 @@ func Configure(options ...Option) {
|
||||
|
||||
// LdJSONFormatter formats the event log as line-delimited JSON
|
||||
var LdJSONFormatter = func() {
|
||||
logrus.SetFormatter(&logrus.PoliteJSONFormatter{})
|
||||
logrus.SetFormatter(&PoliteJSONFormatter{})
|
||||
}
|
||||
|
||||
var TextFormatter = func() {
|
||||
|
||||
18
util/eventlog/polite_json_formatter.go
Normal file
18
util/eventlog/polite_json_formatter.go
Normal file
@ -0,0 +1,18 @@
|
||||
package eventlog
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/maybebtc/logrus"
|
||||
)
|
||||
|
||||
type PoliteJSONFormatter struct{}
|
||||
|
||||
func (f *PoliteJSONFormatter) Format(entry *logrus.Entry) ([]byte, error) {
|
||||
serialized, err := json.Marshal(entry.Data)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Failed to marshal fields to JSON, %v", err)
|
||||
}
|
||||
return append(serialized, '\n'), nil
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user