use formatters directory

This commit is contained in:
Alexander Demidov 2015-03-05 23:31:39 +06:00
parent 75cc3dd51a
commit 3cc6fcc521
2 changed files with 5 additions and 4 deletions

View File

@ -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
`DisableColors` field to `true`
* `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
logrus.SetFormatter(&logrus.LogstashFormatter{Type: “application_name"})
logrus.SetFormatter(&logrus_logstash.LogstashFormatter{Type: “application_name"})
```
Third party logging formatters:

View File

@ -1,8 +1,9 @@
package logrus
package logrus_logstash
import (
"encoding/json"
"fmt"
"github.com/Sirupsen/logrus"
"time"
)
@ -12,7 +13,7 @@ type LogstashFormatter struct {
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["@timestamp"] = entry.Time.Format(time.RFC3339)