logrus/json_formatter.go

20 lines
349 B
Go
Raw Normal View History

2014-03-10 23:22:08 +00:00
package logrus
import (
"encoding/json"
"fmt"
)
type JSONFormatter struct {
}
func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) {
2014-07-27 02:22:39 +00:00
prefixFieldClashes(entry)
2014-03-10 23:22:08 +00:00
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
}