mirror of https://github.com/sirupsen/logrus.git
use formatters directory
This commit is contained in:
parent
75cc3dd51a
commit
3cc6fcc521
|
@ -321,10 +321,10 @@ The built-in logging formatters are:
|
||||||
field to `true`. To force no colored output even if there is a TTY set the
|
field to `true`. To force no colored output even if there is a TTY set the
|
||||||
`DisableColors` field to `true`
|
`DisableColors` field to `true`
|
||||||
* `logrus.JSONFormatter`. Logs fields as JSON.
|
* `logrus.JSONFormatter`. Logs fields as JSON.
|
||||||
* `logrus.LogstashFormatter`. Logs fields as Logstash Events (http://logstash.net).
|
* `logrus_logstash.LogstashFormatter`. Logs fields as Logstash Events (http://logstash.net).
|
||||||
|
|
||||||
```go
|
```go
|
||||||
logrus.SetFormatter(&logrus.LogstashFormatter{Type: “application_name"})
|
logrus.SetFormatter(&logrus_logstash.LogstashFormatter{Type: “application_name"})
|
||||||
```
|
```
|
||||||
|
|
||||||
Third party logging formatters:
|
Third party logging formatters:
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
package logrus
|
package logrus_logstash
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/Sirupsen/logrus"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -12,7 +13,7 @@ type LogstashFormatter struct {
|
||||||
Type string // if not empty use for logstash type field.
|
Type string // if not empty use for logstash type field.
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *LogstashFormatter) Format(entry *Entry) ([]byte, error) {
|
func (f *LogstashFormatter) Format(entry *logrus.Entry) ([]byte, error) {
|
||||||
entry.Data["@version"] = 1
|
entry.Data["@version"] = 1
|
||||||
entry.Data["@timestamp"] = entry.Time.Format(time.RFC3339)
|
entry.Data["@timestamp"] = entry.Time.Format(time.RFC3339)
|
||||||
|
|
Loading…
Reference in New Issue