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:
Brian Tiger Chow 2014-11-16 09:49:38 -08:00
parent 884d629a56
commit ddb0189b90
2 changed files with 19 additions and 1 deletions

View File

@ -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() {

View 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
}