• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

hooks/H05-Dec-2017-260180

.gitignoreH A D05-Dec-20177 21

.travis.ymlH A D05-Dec-2017313 1615

CHANGELOG.mdH A D05-Dec-20172.5 KiB11972

LICENSEH A D05-Dec-20171.1 KiB2217

README.mdH A D05-Dec-201722 KiB510400

alt_exit.goH A D05-Dec-20172.2 KiB6526

alt_exit_test.goH A D05-Dec-20171.6 KiB8467

appveyor.ymlH A D05-Dec-2017281 1514

doc.goH A D05-Dec-2017586 271

entry.goH A D05-Dec-20176.8 KiB280206

entry_test.goH A D05-Dec-20171.4 KiB7857

example_basic_test.goH A D05-Dec-20172 KiB7046

example_hook_test.goH A D05-Dec-20171,001 3625

exported.goH A D05-Dec-20174.8 KiB194116

formatter.goH A D05-Dec-20171.3 KiB4617

formatter_bench_test.goH A D05-Dec-20172.1 KiB10286

hook_test.goH A D05-Dec-20172.5 KiB145117

hooks.goH A D05-Dec-20171.1 KiB3519

json_formatter.goH A D05-Dec-20171.8 KiB8049

json_formatter_test.goH A D05-Dec-20174.4 KiB200164

logger.goH A D05-Dec-20177.9 KiB324244

logger_bench_test.goH A D05-Dec-20171.3 KiB6254

logrus.goH A D05-Dec-20173.6 KiB144104

logrus_test.goH A D05-Dec-20178.9 KiB387311

terminal_bsd.goH A D05-Dec-2017186 114

terminal_check_appengine.goH A D05-Dec-2017111 127

terminal_check_notappengine.goH A D05-Dec-2017252 2014

terminal_linux.goH A D05-Dec-2017320 154

text_formatter.goH A D05-Dec-20174 KiB179136

text_formatter_test.goH A D05-Dec-20173.6 KiB142117

writer.goH A D05-Dec-20171.2 KiB6351

README.md

1# Logrus <img src="http://i.imgur.com/hTeVwmJ.png" width="40" height="40" alt=":walrus:" class="emoji" title=":walrus:"/>&nbsp;[![Build Status](https://travis-ci.org/sirupsen/logrus.svg?branch=master)](https://travis-ci.org/sirupsen/logrus)&nbsp;[![GoDoc](https://godoc.org/github.com/sirupsen/logrus?status.svg)](https://godoc.org/github.com/sirupsen/logrus)
2
3Logrus is a structured logger for Go (golang), completely API compatible with
4the standard library logger.
5
6**Seeing weird case-sensitive problems?** It's in the past been possible to
7import Logrus as both upper- and lower-case. Due to the Go package environment,
8this caused issues in the community and we needed a standard. Some environments
9experienced problems with the upper-case variant, so the lower-case was decided.
10Everything using `logrus` will need to use the lower-case:
11`github.com/sirupsen/logrus`. Any package that isn't, should be changed.
12
13To fix Glide, see [these
14comments](https://github.com/sirupsen/logrus/issues/553#issuecomment-306591437).
15For an in-depth explanation of the casing issue, see [this
16comment](https://github.com/sirupsen/logrus/issues/570#issuecomment-313933276).
17
18**Are you interested in assisting in maintaining Logrus?** Currently I have a
19lot of obligations, and I am unable to provide Logrus with the maintainership it
20needs. If you'd like to help, please reach out to me at `simon at author's
21username dot com`.
22
23Nicely color-coded in development (when a TTY is attached, otherwise just
24plain text):
25
26![Colored](http://i.imgur.com/PY7qMwd.png)
27
28With `log.SetFormatter(&log.JSONFormatter{})`, for easy parsing by logstash
29or Splunk:
30
31```json
32{"animal":"walrus","level":"info","msg":"A group of walrus emerges from the
33ocean","size":10,"time":"2014-03-10 19:57:38.562264131 -0400 EDT"}
34
35{"level":"warning","msg":"The group's number increased tremendously!",
36"number":122,"omg":true,"time":"2014-03-10 19:57:38.562471297 -0400 EDT"}
37
38{"animal":"walrus","level":"info","msg":"A giant walrus appears!",
39"size":10,"time":"2014-03-10 19:57:38.562500591 -0400 EDT"}
40
41{"animal":"walrus","level":"info","msg":"Tremendously sized cow enters the ocean.",
42"size":9,"time":"2014-03-10 19:57:38.562527896 -0400 EDT"}
43
44{"level":"fatal","msg":"The ice breaks!","number":100,"omg":true,
45"time":"2014-03-10 19:57:38.562543128 -0400 EDT"}
46```
47
48With the default `log.SetFormatter(&log.TextFormatter{})` when a TTY is not
49attached, the output is compatible with the
50[logfmt](http://godoc.org/github.com/kr/logfmt) format:
51
52```text
53time="2015-03-26T01:27:38-04:00" level=debug msg="Started observing beach" animal=walrus number=8
54time="2015-03-26T01:27:38-04:00" level=info msg="A group of walrus emerges from the ocean" animal=walrus size=10
55time="2015-03-26T01:27:38-04:00" level=warning msg="The group's number increased tremendously!" number=122 omg=true
56time="2015-03-26T01:27:38-04:00" level=debug msg="Temperature changes" temperature=-4
57time="2015-03-26T01:27:38-04:00" level=panic msg="It's over 9000!" animal=orca size=9009
58time="2015-03-26T01:27:38-04:00" level=fatal msg="The ice breaks!" err=&{0x2082280c0 map[animal:orca size:9009] 2015-03-26 01:27:38.441574009 -0400 EDT panic It's over 9000!} number=100 omg=true
59exit status 1
60```
61
62#### Case-sensitivity
63
64The organization's name was changed to lower-case--and this will not be changed
65back. If you are getting import conflicts due to case sensitivity, please use
66the lower-case import: `github.com/sirupsen/logrus`.
67
68#### Example
69
70The simplest way to use Logrus is simply the package-level exported logger:
71
72```go
73package main
74
75import (
76  log "github.com/sirupsen/logrus"
77)
78
79func main() {
80  log.WithFields(log.Fields{
81    "animal": "walrus",
82  }).Info("A walrus appears")
83}
84```
85
86Note that it's completely api-compatible with the stdlib logger, so you can
87replace your `log` imports everywhere with `log "github.com/sirupsen/logrus"`
88and you'll now have the flexibility of Logrus. You can customize it all you
89want:
90
91```go
92package main
93
94import (
95  "os"
96  log "github.com/sirupsen/logrus"
97)
98
99func init() {
100  // Log as JSON instead of the default ASCII formatter.
101  log.SetFormatter(&log.JSONFormatter{})
102
103  // Output to stdout instead of the default stderr
104  // Can be any io.Writer, see below for File example
105  log.SetOutput(os.Stdout)
106
107  // Only log the warning severity or above.
108  log.SetLevel(log.WarnLevel)
109}
110
111func main() {
112  log.WithFields(log.Fields{
113    "animal": "walrus",
114    "size":   10,
115  }).Info("A group of walrus emerges from the ocean")
116
117  log.WithFields(log.Fields{
118    "omg":    true,
119    "number": 122,
120  }).Warn("The group's number increased tremendously!")
121
122  log.WithFields(log.Fields{
123    "omg":    true,
124    "number": 100,
125  }).Fatal("The ice breaks!")
126
127  // A common pattern is to re-use fields between logging statements by re-using
128  // the logrus.Entry returned from WithFields()
129  contextLogger := log.WithFields(log.Fields{
130    "common": "this is a common field",
131    "other": "I also should be logged always",
132  })
133
134  contextLogger.Info("I'll be logged with common and other field")
135  contextLogger.Info("Me too")
136}
137```
138
139For more advanced usage such as logging to multiple locations from the same
140application, you can also create an instance of the `logrus` Logger:
141
142```go
143package main
144
145import (
146  "os"
147  "github.com/sirupsen/logrus"
148)
149
150// Create a new instance of the logger. You can have any number of instances.
151var log = logrus.New()
152
153func main() {
154  // The API for setting attributes is a little different than the package level
155  // exported logger. See Godoc.
156  log.Out = os.Stdout
157
158  // You could set this to any `io.Writer` such as a file
159  // file, err := os.OpenFile("logrus.log", os.O_CREATE|os.O_WRONLY, 0666)
160  // if err == nil {
161  //  log.Out = file
162  // } else {
163  //  log.Info("Failed to log to file, using default stderr")
164  // }
165
166  log.WithFields(logrus.Fields{
167    "animal": "walrus",
168    "size":   10,
169  }).Info("A group of walrus emerges from the ocean")
170}
171```
172
173#### Fields
174
175Logrus encourages careful, structured logging through logging fields instead of
176long, unparseable error messages. For example, instead of: `log.Fatalf("Failed
177to send event %s to topic %s with key %d")`, you should log the much more
178discoverable:
179
180```go
181log.WithFields(log.Fields{
182  "event": event,
183  "topic": topic,
184  "key": key,
185}).Fatal("Failed to send event")
186```
187
188We've found this API forces you to think about logging in a way that produces
189much more useful logging messages. We've been in countless situations where just
190a single added field to a log statement that was already there would've saved us
191hours. The `WithFields` call is optional.
192
193In general, with Logrus using any of the `printf`-family functions should be
194seen as a hint you should add a field, however, you can still use the
195`printf`-family functions with Logrus.
196
197#### Default Fields
198
199Often it's helpful to have fields _always_ attached to log statements in an
200application or parts of one. For example, you may want to always log the
201`request_id` and `user_ip` in the context of a request. Instead of writing
202`log.WithFields(log.Fields{"request_id": request_id, "user_ip": user_ip})` on
203every line, you can create a `logrus.Entry` to pass around instead:
204
205```go
206requestLogger := log.WithFields(log.Fields{"request_id": request_id, "user_ip": user_ip})
207requestLogger.Info("something happened on that request") # will log request_id and user_ip
208requestLogger.Warn("something not great happened")
209```
210
211#### Hooks
212
213You can add hooks for logging levels. For example to send errors to an exception
214tracking service on `Error`, `Fatal` and `Panic`, info to StatsD or log to
215multiple places simultaneously, e.g. syslog.
216
217Logrus comes with [built-in hooks](hooks/). Add those, or your custom hook, in
218`init`:
219
220```go
221import (
222  log "github.com/sirupsen/logrus"
223  "gopkg.in/gemnasium/logrus-airbrake-hook.v2" // the package is named "aibrake"
224  logrus_syslog "github.com/sirupsen/logrus/hooks/syslog"
225  "log/syslog"
226)
227
228func init() {
229
230  // Use the Airbrake hook to report errors that have Error severity or above to
231  // an exception tracker. You can create custom hooks, see the Hooks section.
232  log.AddHook(airbrake.NewHook(123, "xyz", "production"))
233
234  hook, err := logrus_syslog.NewSyslogHook("udp", "localhost:514", syslog.LOG_INFO, "")
235  if err != nil {
236    log.Error("Unable to connect to local syslog daemon")
237  } else {
238    log.AddHook(hook)
239  }
240}
241```
242Note: 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).
243
244| Hook  | Description |
245| ----- | ----------- |
246| [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. |
247| [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. |
248| [Amazon Kinesis](https://github.com/evalphobia/logrus_kinesis) | Hook for logging to [Amazon Kinesis](https://aws.amazon.com/kinesis/) |
249| [Amqp-Hook](https://github.com/vladoatanasov/logrus_amqp) | Hook for logging to Amqp broker (Like RabbitMQ) |
250| [AzureTableHook](https://github.com/kpfaulkner/azuretablehook/) | Hook for logging to Azure Table Storage|
251| [Bugsnag](https://github.com/Shopify/logrus-bugsnag/blob/master/bugsnag.go) | Send errors to the Bugsnag exception tracking service. |
252| [DeferPanic](https://github.com/deferpanic/dp-logrus) | Hook for logging to DeferPanic |
253| [Discordrus](https://github.com/kz/discordrus) | Hook for logging to [Discord](https://discordapp.com/) |
254| [ElasticSearch](https://github.com/sohlich/elogrus) | Hook for logging to ElasticSearch|
255| [Firehose](https://github.com/beaubrewer/logrus_firehose) | Hook for logging to [Amazon Firehose](https://aws.amazon.com/kinesis/firehose/)
256| [Fluentd](https://github.com/evalphobia/logrus_fluent) | Hook for logging to fluentd |
257| [Go-Slack](https://github.com/multiplay/go-slack) | Hook for logging to [Slack](https://slack.com) |
258| [Graylog](https://github.com/gemnasium/logrus-graylog-hook) | Hook for logging to [Graylog](http://graylog2.org/) |
259| [Hiprus](https://github.com/nubo/hiprus) | Send errors to a channel in hipchat. |
260| [Honeybadger](https://github.com/agonzalezro/logrus_honeybadger) | Hook for sending exceptions to Honeybadger |
261| [InfluxDB](https://github.com/Abramovic/logrus_influxdb) | Hook for logging to influxdb |
262| [Influxus](http://github.com/vlad-doru/influxus) | Hook for concurrently logging to [InfluxDB](http://influxdata.com/) |
263| [Journalhook](https://github.com/wercker/journalhook) | Hook for logging to `systemd-journald` |
264| [KafkaLogrus](https://github.com/tracer0tong/kafkalogrus) | Hook for logging to Kafka |
265| [LFShook](https://github.com/rifflock/lfshook) | Hook for logging to the local filesystem |
266| [Logbeat](https://github.com/macandmia/logbeat) | Hook for logging to [Opbeat](https://opbeat.com/) |
267| [Logentries](https://github.com/jcftang/logentriesrus) | Hook for logging to [Logentries](https://logentries.com/) |
268| [Logentrus](https://github.com/puddingfactory/logentrus) | Hook for logging to [Logentries](https://logentries.com/) |
269| [Logmatic.io](https://github.com/logmatic/logmatic-go) | Hook for logging to [Logmatic.io](http://logmatic.io/) |
270| [Logrusly](https://github.com/sebest/logrusly) | Send logs to [Loggly](https://www.loggly.com/) |
271| [Logstash](https://github.com/bshuster-repo/logrus-logstash-hook) | Hook for logging to [Logstash](https://www.elastic.co/products/logstash) |
272| [Mail](https://github.com/zbindenren/logrus_mail) | Hook for sending exceptions via mail |
273| [Mattermost](https://github.com/shuLhan/mattermost-integration/tree/master/hooks/logrus) | Hook for logging to [Mattermost](https://mattermost.com/) |
274| [Mongodb](https://github.com/weekface/mgorus) | Hook for logging to mongodb |
275| [NATS-Hook](https://github.com/rybit/nats_logrus_hook) | Hook for logging to [NATS](https://nats.io) |
276| [Octokit](https://github.com/dorajistyle/logrus-octokit-hook) | Hook for logging to github via octokit |
277| [Papertrail](https://github.com/polds/logrus-papertrail-hook) | Send errors to the [Papertrail](https://papertrailapp.com) hosted logging service via UDP. |
278| [PostgreSQL](https://github.com/gemnasium/logrus-postgresql-hook) | Send logs to [PostgreSQL](http://postgresql.org) |
279| [Promrus](https://github.com/weaveworks/promrus) | Expose number of log messages as [Prometheus](https://prometheus.io/) metrics |
280| [Pushover](https://github.com/toorop/logrus_pushover) | Send error via [Pushover](https://pushover.net) |
281| [Raygun](https://github.com/squirkle/logrus-raygun-hook) | Hook for logging to [Raygun.io](http://raygun.io/) |
282| [Redis-Hook](https://github.com/rogierlommers/logrus-redis-hook) | Hook for logging to a ELK stack (through Redis) |
283| [Rollrus](https://github.com/heroku/rollrus) | Hook for sending errors to rollbar |
284| [Scribe](https://github.com/sagar8192/logrus-scribe-hook) | Hook for logging to [Scribe](https://github.com/facebookarchive/scribe)|
285| [Sentry](https://github.com/evalphobia/logrus_sentry) | Send errors to the Sentry error logging and aggregation service. |
286| [Slackrus](https://github.com/johntdyer/slackrus) | Hook for Slack chat. |
287| [Stackdriver](https://github.com/knq/sdhook) | Hook for logging to [Google Stackdriver](https://cloud.google.com/logging/) |
288| [Sumorus](https://github.com/doublefree/sumorus) | Hook for logging to [SumoLogic](https://www.sumologic.com/)|
289| [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. |
290| [Syslog TLS](https://github.com/shinji62/logrus-syslog-ng) | Send errors to remote syslog server with TLS support. |
291| [Telegram](https://github.com/rossmcdonald/telegram_hook) | Hook for logging errors to [Telegram](https://telegram.org/) |
292| [TraceView](https://github.com/evalphobia/logrus_appneta) | Hook for logging to [AppNeta TraceView](https://www.appneta.com/products/traceview/) |
293| [Typetalk](https://github.com/dragon3/logrus-typetalk-hook) | Hook for logging to [Typetalk](https://www.typetalk.in/) |
294| [logz.io](https://github.com/ripcurld00d/logrus-logzio-hook) | Hook for logging to [logz.io](https://logz.io), a Log as a Service using Logstash |
295| [SQS-Hook](https://github.com/tsarpaul/logrus_sqs) | Hook for logging to [Amazon Simple Queue Service (SQS)](https://aws.amazon.com/sqs/) |
296
297#### Level logging
298
299Logrus has six logging levels: Debug, Info, Warning, Error, Fatal and Panic.
300
301```go
302log.Debug("Useful debugging information.")
303log.Info("Something noteworthy happened!")
304log.Warn("You should probably take a look at this.")
305log.Error("Something failed but I'm not quitting.")
306// Calls os.Exit(1) after logging
307log.Fatal("Bye.")
308// Calls panic() after logging
309log.Panic("I'm bailing.")
310```
311
312You can set the logging level on a `Logger`, then it will only log entries with
313that severity or anything above it:
314
315```go
316// Will log anything that is info or above (warn, error, fatal, panic). Default.
317log.SetLevel(log.InfoLevel)
318```
319
320It may be useful to set `log.Level = logrus.DebugLevel` in a debug or verbose
321environment if your application has that.
322
323#### Entries
324
325Besides the fields added with `WithField` or `WithFields` some fields are
326automatically added to all logging events:
327
3281. `time`. The timestamp when the entry was created.
3292. `msg`. The logging message passed to `{Info,Warn,Error,Fatal,Panic}` after
330   the `AddFields` call. E.g. `Failed to send event.`
3313. `level`. The logging level. E.g. `info`.
332
333#### Environments
334
335Logrus has no notion of environment.
336
337If you wish for hooks and formatters to only be used in specific environments,
338you should handle that yourself. For example, if your application has a global
339variable `Environment`, which is a string representation of the environment you
340could do:
341
342```go
343import (
344  log "github.com/sirupsen/logrus"
345)
346
347init() {
348  // do something here to set environment depending on an environment variable
349  // or command-line flag
350  if Environment == "production" {
351    log.SetFormatter(&log.JSONFormatter{})
352  } else {
353    // The TextFormatter is default, you don't actually have to do this.
354    log.SetFormatter(&log.TextFormatter{})
355  }
356}
357```
358
359This configuration is how `logrus` was intended to be used, but JSON in
360production is mostly only useful if you do log aggregation with tools like
361Splunk or Logstash.
362
363#### Formatters
364
365The built-in logging formatters are:
366
367* `logrus.TextFormatter`. Logs the event in colors if stdout is a tty, otherwise
368  without colors.
369  * *Note:* to force colored output when there is no TTY, set the `ForceColors`
370    field to `true`.  To force no colored output even if there is a TTY  set the
371    `DisableColors` field to `true`. For Windows, see
372    [github.com/mattn/go-colorable](https://github.com/mattn/go-colorable).
373  * All options are listed in the [generated docs](https://godoc.org/github.com/sirupsen/logrus#TextFormatter).
374* `logrus.JSONFormatter`. Logs fields as JSON.
375  * All options are listed in the [generated docs](https://godoc.org/github.com/sirupsen/logrus#JSONFormatter).
376
377Third party logging formatters:
378
379* [`FluentdFormatter`](https://github.com/joonix/log). Formats entries that can be parsed by Kubernetes and Google Container Engine.
380* [`logstash`](https://github.com/bshuster-repo/logrus-logstash-hook). Logs fields as [Logstash](http://logstash.net) Events.
381* [`prefixed`](https://github.com/x-cray/logrus-prefixed-formatter). Displays log entry source along with alternative layout.
382* [`zalgo`](https://github.com/aybabtme/logzalgo). Invoking the P͉̫o̳̼̊w̖͈̰͎e̬͔̭͂r͚̼̹̲ ̫͓͉̳͈ō̠͕͖̚f̝͍̠ ͕̲̞͖͑Z̖̫̤̫ͪa͉̬͈̗l͖͎g̳̥o̰̥̅!̣͔̲̻͊̄ ̙̘̦̹̦.
383
384You can define your formatter by implementing the `Formatter` interface,
385requiring a `Format` method. `Format` takes an `*Entry`. `entry.Data` is a
386`Fields` type (`map[string]interface{}`) with all your fields as well as the
387default ones (see Entries section above):
388
389```go
390type MyJSONFormatter struct {
391}
392
393log.SetFormatter(new(MyJSONFormatter))
394
395func (f *MyJSONFormatter) Format(entry *Entry) ([]byte, error) {
396  // Note this doesn't include Time, Level and Message which are available on
397  // the Entry. Consult `godoc` on information about those fields or read the
398  // source of the official loggers.
399  serialized, err := json.Marshal(entry.Data)
400    if err != nil {
401      return nil, fmt.Errorf("Failed to marshal fields to JSON, %v", err)
402    }
403  return append(serialized, '\n'), nil
404}
405```
406
407#### Logger as an `io.Writer`
408
409Logrus can be transformed into an `io.Writer`. That writer is the end of an `io.Pipe` and it is your responsibility to close it.
410
411```go
412w := logger.Writer()
413defer w.Close()
414
415srv := http.Server{
416    // create a stdlib log.Logger that writes to
417    // logrus.Logger.
418    ErrorLog: log.New(w, "", 0),
419}
420```
421
422Each line written to that writer will be printed the usual way, using formatters
423and hooks. The level for those entries is `info`.
424
425This means that we can override the standard library logger easily:
426
427```go
428logger := logrus.New()
429logger.Formatter = &logrus.JSONFormatter{}
430
431// Use logrus for standard log output
432// Note that `log` here references stdlib's log
433// Not logrus imported under the name `log`.
434log.SetOutput(logger.Writer())
435```
436
437#### Rotation
438
439Log rotation is not provided with Logrus. Log rotation should be done by an
440external program (like `logrotate(8)`) that can compress and delete old log
441entries. It should not be a feature of the application-level logger.
442
443#### Tools
444
445| Tool | Description |
446| ---- | ----------- |
447|[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.|
448|[Logrus Viper Helper](https://github.com/heirko/go-contrib/tree/master/logrusHelper)|An Helper around Logrus to wrap with spf13/Viper to load configuration with fangs! And to simplify Logrus configuration use some behavior of [Logrus Mate](https://github.com/gogap/logrus_mate). [sample](https://github.com/heirko/iris-contrib/blob/master/middleware/logrus-logger/example) |
449
450#### Testing
451
452Logrus has a built in facility for asserting the presence of log messages. This is implemented through the `test` hook and provides:
453
454* decorators for existing logger (`test.NewLocal` and `test.NewGlobal`) which basically just add the `test` hook
455* a test logger (`test.NewNullLogger`) that just records log messages (and does not output any):
456
457```go
458import(
459  "github.com/sirupsen/logrus"
460  "github.com/sirupsen/logrus/hooks/test"
461  "github.com/stretchr/testify/assert"
462  "testing"
463)
464
465func TestSomething(t*testing.T){
466  logger, hook := test.NewNullLogger()
467  logger.Error("Helloerror")
468
469  assert.Equal(t, 1, len(hook.Entries))
470  assert.Equal(t, logrus.ErrorLevel, hook.LastEntry().Level)
471  assert.Equal(t, "Helloerror", hook.LastEntry().Message)
472
473  hook.Reset()
474  assert.Nil(t, hook.LastEntry())
475}
476```
477
478#### Fatal handlers
479
480Logrus can register one or more functions that will be called when any `fatal`
481level message is logged. The registered handlers will be executed before
482logrus performs a `os.Exit(1)`. This behavior may be helpful if callers need
483to gracefully shutdown. Unlike a `panic("Something went wrong...")` call which can be intercepted with a deferred `recover` a call to `os.Exit(1)` can not be intercepted.
484
485```
486...
487handler := func() {
488  // gracefully shutdown something...
489}
490logrus.RegisterExitHandler(handler)
491...
492```
493
494#### Thread safety
495
496By default Logger is protected by mutex for concurrent writes, this mutex is invoked when calling hooks and writing logs.
497If you are sure such locking is not needed, you can call logger.SetNoLock() to disable the locking.
498
499Situation when locking is not needed includes:
500
501* You have no hooks registered, or hooks calling is already thread-safe.
502
503* Writing to logger.Out is already thread-safe, for example:
504
505  1) logger.Out is protected by locks.
506
507  2) logger.Out is a os.File handler opened with `O_APPEND` flag, and every write is smaller than 4k. (This allow multi-thread/multi-process writing)
508
509     (Refer to http://www.notthewizard.com/2014/06/17/are-files-appends-really-atomic/)
510