https://github.com/seatgeek/logrus-gelf-formatter
Formats logrus messages in the GELF JSON format
https://github.com/seatgeek/logrus-gelf-formatter
Last synced: 3 months ago
JSON representation
Formats logrus messages in the GELF JSON format
- Host: GitHub
- URL: https://github.com/seatgeek/logrus-gelf-formatter
- Owner: seatgeek
- License: bsd-3-clause
- Created: 2017-07-21T13:04:20.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2021-04-14T08:08:42.000Z (about 4 years ago)
- Last Synced: 2024-06-18T20:08:06.404Z (11 months ago)
- Language: Go
- Size: 9.77 KB
- Stars: 3
- Watchers: 5
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Logrus GELF Log Formatter
[Logrus](https://github.com/sirupsen/logrus) Only a formatter, outputs the log message in the GELF JSON format as decribed by Graylog 2.If you are looking for a GELF hook capable of sending directly to graylog, please use this: https://github.com/gemnasium/logrus-graylog-hook
The reason for using just a formatter is that you can write files or directly to stdout in the expected format and then separately ship the
lines to graylog, without stealing CPU time from your go app.## Installation
To install formatter, use `go get`:```sh
$ go get github.com/seatgeek/logrus-gelf-formatter
```## Usage
Here is how it should be used:```go
package mainimport (
"github.com/sirupsen/logrus"
gelf "github.com/seatgeek/logrus-gelf-formatter"
)var log = logrus.New()
func init() {
log.Formatter = new(gelf.GelfFormatter)
log.Level = logrus.DebugLevel
}func main() {
log.WithFields(logrus.Fields{
"prefix": "main",
"animal": "walrus",
"number": 8,
}).Debug("Started observing beach")log.WithFields(logrus.Fields{
"prefix": "sensor",
"temperature": -4,
}).Info("Temperature changes")
}
```