|
|
|
@ -75,17 +75,12 @@ package main
|
|
|
|
|
import (
|
|
|
|
|
"os"
|
|
|
|
|
log "github.com/Sirupsen/logrus"
|
|
|
|
|
"github.com/Sirupsen/logrus/hooks/airbrake"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
// Log as JSON instead of the default ASCII formatter.
|
|
|
|
|
log.SetFormatter(&log.JSONFormatter{})
|
|
|
|
|
|
|
|
|
|
// Use the Airbrake hook to report errors that have Error severity or above to
|
|
|
|
|
// an exception tracker. You can create custom hooks, see the Hooks section.
|
|
|
|
|
log.AddHook(airbrake.NewHook("https://example.com", "xyz", "development"))
|
|
|
|
|
|
|
|
|
|
// Output to stderr instead of stdout, could also be a file.
|
|
|
|
|
log.SetOutput(os.Stderr)
|
|
|
|
|
|
|
|
|
@ -182,13 +177,16 @@ Logrus comes with [built-in hooks](hooks/). Add those, or your custom hook, in
|
|
|
|
|
```go
|
|
|
|
|
import (
|
|
|
|
|
log "github.com/Sirupsen/logrus"
|
|
|
|
|
"github.com/Sirupsen/logrus/hooks/airbrake"
|
|
|
|
|
"gopkg.in/gemnasium/logrus-airbrake-hook.v2" // the package is named "aibrake"
|
|
|
|
|
logrus_syslog "github.com/Sirupsen/logrus/hooks/syslog"
|
|
|
|
|
"log/syslog"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
log.AddHook(airbrake.NewHook("https://example.com", "xyz", "development"))
|
|
|
|
|
|
|
|
|
|
// Use the Airbrake hook to report errors that have Error severity or above to
|
|
|
|
|
// an exception tracker. You can create custom hooks, see the Hooks section.
|
|
|
|
|
log.AddHook(airbrake.NewHook(123, "xyz", "production"))
|
|
|
|
|
|
|
|
|
|
hook, err := logrus_syslog.NewSyslogHook("udp", "localhost:514", syslog.LOG_INFO, "")
|
|
|
|
|
if err != nil {
|
|
|
|
@ -198,20 +196,21 @@ func init() {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Note: Syslog hook also support connecting to local syslog (Ex. "/dev/log" or "/var/run/syslog" or "/var/run/log"). For the detail, please check the [syslog hook README](hooks/syslog/README.md).
|
|
|
|
|
|
|
|
|
|
| Hook | Description |
|
|
|
|
|
| ----- | ----------- |
|
|
|
|
|
| [Airbrake](https://github.com/Sirupsen/logrus/blob/master/hooks/airbrake/airbrake.go) | Send errors to an exception tracking service compatible with the Airbrake API. Uses [`airbrake-go`](https://github.com/tobi/airbrake-go) behind the scenes. |
|
|
|
|
|
| [Papertrail](https://github.com/Sirupsen/logrus/blob/master/hooks/papertrail/papertrail.go) | Send errors to the Papertrail hosted logging service via UDP. |
|
|
|
|
|
| [Airbrake](https://github.com/gemnasium/logrus-airbrake-hook) | Send errors to the Airbrake API V3. Uses the official [`gobrake`](https://github.com/airbrake/gobrake) behind the scenes. |
|
|
|
|
|
| [Airbrake "legacy"](https://github.com/gemnasium/logrus-airbrake-legacy-hook) | Send errors to an exception tracking service compatible with the Airbrake API V2. Uses [`airbrake-go`](https://github.com/tobi/airbrake-go) behind the scenes. |
|
|
|
|
|
| [Papertrail](https://github.com/polds/logrus-papertrail-hook) | Send errors to the [Papertrail](https://papertrailapp.com) hosted logging service via UDP. |
|
|
|
|
|
| [Syslog](https://github.com/Sirupsen/logrus/blob/master/hooks/syslog/syslog.go) | Send errors to remote syslog server. Uses standard library `log/syslog` behind the scenes. |
|
|
|
|
|
| [BugSnag](https://github.com/Sirupsen/logrus/blob/master/hooks/bugsnag/bugsnag.go) | Send errors to the Bugsnag exception tracking service. |
|
|
|
|
|
| [Sentry](https://github.com/Sirupsen/logrus/blob/master/hooks/sentry/sentry.go) | Send errors to the Sentry error logging and aggregation service. |
|
|
|
|
|
| [Bugsnag](https://github.com/Shopify/logrus-bugsnag/blob/master/bugsnag.go) | Send errors to the Bugsnag exception tracking service. |
|
|
|
|
|
| [Sentry](https://github.com/evalphobia/logrus_sentry) | Send errors to the Sentry error logging and aggregation service. |
|
|
|
|
|
| [Hiprus](https://github.com/nubo/hiprus) | Send errors to a channel in hipchat. |
|
|
|
|
|
| [Logrusly](https://github.com/sebest/logrusly) | Send logs to [Loggly](https://www.loggly.com/) |
|
|
|
|
|
| [Slackrus](https://github.com/johntdyer/slackrus) | Hook for Slack chat. |
|
|
|
|
|
| [Journalhook](https://github.com/wercker/journalhook) | Hook for logging to `systemd-journald` |
|
|
|
|
|
| [Graylog](https://github.com/gemnasium/logrus-hooks/tree/master/graylog) | Hook for logging to [Graylog](http://graylog2.org/) |
|
|
|
|
|
| [Graylog](https://github.com/gemnasium/logrus-graylog-hook) | Hook for logging to [Graylog](http://graylog2.org/) |
|
|
|
|
|
| [Raygun](https://github.com/squirkle/logrus-raygun-hook) | Hook for logging to [Raygun.io](http://raygun.io/) |
|
|
|
|
|
| [LFShook](https://github.com/rifflock/lfshook) | Hook for logging to the local filesystem |
|
|
|
|
|
| [Honeybadger](https://github.com/agonzalezro/logrus_honeybadger) | Hook for sending exceptions to Honeybadger |
|
|
|
|
@ -219,6 +218,10 @@ func init() {
|
|
|
|
|
| [Rollrus](https://github.com/heroku/rollrus) | Hook for sending errors to rollbar |
|
|
|
|
|
| [Fluentd](https://github.com/evalphobia/logrus_fluent) | Hook for logging to fluentd |
|
|
|
|
|
| [Mongodb](https://github.com/weekface/mgorus) | Hook for logging to mongodb |
|
|
|
|
|
| [InfluxDB](https://github.com/Abramovic/logrus_influxdb) | Hook for logging to influxdb |
|
|
|
|
|
| [Octokit](https://github.com/dorajistyle/logrus-octokit-hook) | Hook for logging to github via octokit |
|
|
|
|
|
| [DeferPanic](https://github.com/deferpanic/dp-logrus) | Hook for logging to DeferPanic |
|
|
|
|
|
| [Redis-Hook](https://github.com/rogierlommers/logrus-redis-hook) | Hook for logging to a ELK stack (through Redis) |
|
|
|
|
|
|
|
|
|
|
#### Level logging
|
|
|
|
|
|
|
|
|
@ -296,15 +299,16 @@ 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_logstash.LogstashFormatter`. Logs fields as Logstash Events (http://logstash.net).
|
|
|
|
|
* `logrus/formatters/logstash.LogstashFormatter`. Logs fields as [Logstash](http://logstash.net) Events.
|
|
|
|
|
|
|
|
|
|
```go
|
|
|
|
|
logrus.SetFormatter(&logrus_logstash.LogstashFormatter{Type: “application_name"})
|
|
|
|
|
logrus.SetFormatter(&logstash.LogstashFormatter{Type: "application_name"})
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
Third party logging formatters:
|
|
|
|
|
|
|
|
|
|
* [`zalgo`](https://github.com/aybabtme/logzalgo): invoking the P͉̫o̳̼̊w̖͈̰͎e̬͔̭͂r͚̼̹̲ ̫͓͉̳͈ō̠͕͖̚f̝͍̠ ͕̲̞͖͑Z̖̫̤̫ͪa͉̬͈̗l͖͎g̳̥o̰̥̅!̣͔̲̻͊̄ ̙̘̦̹̦.
|
|
|
|
|
* [`prefixed`](https://github.com/x-cray/logrus-prefixed-formatter). Displays log entry source along with alternative layout.
|
|
|
|
|
* [`zalgo`](https://github.com/aybabtme/logzalgo). Invoking the P͉̫o̳̼̊w̖͈̰͎e̬͔̭͂r͚̼̹̲ ̫͓͉̳͈ō̠͕͖̚f̝͍̠ ͕̲̞͖͑Z̖̫̤̫ͪa͉̬͈̗l͖͎g̳̥o̰̥̅!̣͔̲̻͊̄ ̙̘̦̹̦.
|
|
|
|
|
|
|
|
|
|
You can define your formatter by implementing the `Formatter` interface,
|
|
|
|
|
requiring a `Format` method. `Format` takes an `*Entry`. `entry.Data` is a
|
|
|
|
@ -353,5 +357,10 @@ Log rotation is not provided with Logrus. Log rotation should be done by an
|
|
|
|
|
external program (like `logrotate(8)`) that can compress and delete old log
|
|
|
|
|
entries. It should not be a feature of the application-level logger.
|
|
|
|
|
|
|
|
|
|
#### Tools
|
|
|
|
|
|
|
|
|
|
| Tool | Description |
|
|
|
|
|
| ---- | ----------- |
|
|
|
|
|
|[Logrus Mate](https://github.com/gogap/logrus_mate)|Logrus mate is a tool for Logrus to manage loggers, you can initial logger's level, hook and formatter by config file, the logger will generated with different config at different environment.|
|
|
|
|
|
|
|
|
|
|
[godoc]: https://godoc.org/github.com/Sirupsen/logrus
|
|
|
|
|