summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/Sirupsen/logrus/json_formatter.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2017-03-25 20:45:10 +0100
committerWim <wim@42.be>2017-03-25 20:45:10 +0100
commit07fd825349e8b7e86f8afb3843cb8e2c2afc7c74 (patch)
treeea4b33872a5b925fa0ecd2b421f8f073ba22b2cc /vendor/github.com/Sirupsen/logrus/json_formatter.go
parentbe15cc8a36ed3c207251f9b92815781f2fa8618d (diff)
downloadmatterbridge-msglm-07fd825349e8b7e86f8afb3843cb8e2c2afc7c74.tar.gz
matterbridge-msglm-07fd825349e8b7e86f8afb3843cb8e2c2afc7c74.tar.bz2
matterbridge-msglm-07fd825349e8b7e86f8afb3843cb8e2c2afc7c74.zip
Update vendor
Diffstat (limited to 'vendor/github.com/Sirupsen/logrus/json_formatter.go')
-rw-r--r--vendor/github.com/Sirupsen/logrus/json_formatter.go39
1 files changed, 36 insertions, 3 deletions
diff --git a/vendor/github.com/Sirupsen/logrus/json_formatter.go b/vendor/github.com/Sirupsen/logrus/json_formatter.go
index 2ad6dc5c..266554e9 100644
--- a/vendor/github.com/Sirupsen/logrus/json_formatter.go
+++ b/vendor/github.com/Sirupsen/logrus/json_formatter.go
@@ -5,9 +5,40 @@ import (
"fmt"
)
+type fieldKey string
+type FieldMap map[fieldKey]string
+
+const (
+ FieldKeyMsg = "msg"
+ FieldKeyLevel = "level"
+ FieldKeyTime = "time"
+)
+
+func (f FieldMap) resolve(key fieldKey) string {
+ if k, ok := f[key]; ok {
+ return k
+ }
+
+ return string(key)
+}
+
type JSONFormatter struct {
// TimestampFormat sets the format used for marshaling timestamps.
TimestampFormat string
+
+ // DisableTimestamp allows disabling automatic timestamps in output
+ DisableTimestamp bool
+
+ // FieldMap allows users to customize the names of keys for various fields.
+ // As an example:
+ // formatter := &JSONFormatter{
+ // FieldMap: FieldMap{
+ // FieldKeyTime: "@timestamp",
+ // FieldKeyLevel: "@level",
+ // FieldKeyLevel: "@message",
+ // },
+ // }
+ FieldMap FieldMap
}
func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) {
@@ -29,9 +60,11 @@ func (f *JSONFormatter) Format(entry *Entry) ([]byte, error) {
timestampFormat = DefaultTimestampFormat
}
- data["time"] = entry.Time.Format(timestampFormat)
- data["msg"] = entry.Message
- data["level"] = entry.Level.String()
+ if !f.DisableTimestamp {
+ data[f.FieldMap.resolve(FieldKeyTime)] = entry.Time.Format(timestampFormat)
+ }
+ data[f.FieldMap.resolve(FieldKeyMsg)] = entry.Message
+ data[f.FieldMap.resolve(FieldKeyLevel)] = entry.Level.String()
serialized, err := json.Marshal(data)
if err != nil {