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