You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
log.Error("Unable to connect to local syslog daemon")
286
+
logrus.Error("Unable to connect to local syslog daemon")
283
287
} else {
284
-
log.AddHook(hook)
288
+
logrus.AddHook(hook)
285
289
}
286
290
}
287
291
```
@@ -295,29 +299,29 @@ A list of currently known service hooks can be found in this wiki [page](https:/
295
299
Logrus has seven logging levels: Trace, Debug, Info, Warning, Error, Fatal and Panic.
296
300
297
301
```go
298
-
log.Trace("Something very low level.")
299
-
log.Debug("Useful debugging information.")
300
-
log.Info("Something noteworthy happened!")
301
-
log.Warn("You should probably take a look at this.")
302
-
log.Error("Something failed but I'm not quitting.")
302
+
logrus.Trace("Something very low level.")
303
+
logrus.Debug("Useful debugging information.")
304
+
logrus.Info("Something noteworthy happened!")
305
+
logrus.Warn("You should probably take a look at this.")
306
+
logrus.Error("Something failed but I'm not quitting.")
303
307
// Calls os.Exit(1) after logging
304
-
log.Fatal("Bye.")
308
+
logrus.Fatal("Bye.")
305
309
// Calls panic() after logging
306
-
log.Panic("I'm bailing.")
310
+
logrus.Panic("I'm bailing.")
307
311
```
308
312
309
313
You can set the logging level on a `Logger`, then it will only log entries with
310
314
that severity or anything above it:
311
315
312
316
```go
313
317
// Will log anything that is info or above (warn, error, fatal, panic). Default.
314
-
log.SetLevel(log.InfoLevel)
318
+
logrus.SetLevel(logrus.InfoLevel)
315
319
```
316
320
317
-
It may be useful to set `log.Level = logrus.DebugLevel` in a debug or verbose
321
+
It may be useful to set `logrus.Level = logrus.DebugLevel` in a debug or verbose
318
322
environment if your application has that.
319
323
320
-
Note: If you want different log levels for global (`log.SetLevel(...)`) and syslog logging, please check the [syslog hook README](hooks/syslog/README.md#different-log-levels-for-local-and-remote-logging).
324
+
Note: If you want different log levels for global (`logrus.SetLevel(...)`) and syslog logging, please check the [syslog hook README](hooks/syslog/README.md#different-log-levels-for-local-and-remote-logging).
321
325
322
326
#### Entries
323
327
@@ -340,17 +344,17 @@ could do:
340
344
341
345
```go
342
346
import (
343
-
log "github.com/sirupsen/logrus"
347
+
"github.com/sirupsen/logrus"
344
348
)
345
349
346
350
funcinit() {
347
351
// do something here to set environment depending on an environment variable
348
352
// or command-line flag
349
353
if Environment == "production" {
350
-
log.SetFormatter(&log.JSONFormatter{})
354
+
logrus.SetFormatter(&logrus.JSONFormatter{})
351
355
} else {
352
356
// The TextFormatter is default, you don't actually have to do this.
353
-
log.SetFormatter(&log.TextFormatter{})
357
+
logrus.SetFormatter(&logrus.TextFormatter{})
354
358
}
355
359
}
356
360
```
@@ -393,10 +397,9 @@ requiring a `Format` method. `Format` takes an `*Entry`. `entry.Data` is a
// Note this doesn't include Time, Level and Message which are available on
@@ -462,10 +465,11 @@ Logrus has a built-in facility for asserting the presence of log messages. This
462
465
463
466
```go
464
467
import(
468
+
"testing"
469
+
465
470
"github.com/sirupsen/logrus"
466
471
"github.com/sirupsen/logrus/hooks/test"
467
472
"github.com/stretchr/testify/assert"
468
-
"testing"
469
473
)
470
474
471
475
funcTestSomething(t*testing.T){
@@ -488,13 +492,13 @@ level message is logged. The registered handlers will be executed before
488
492
logrus performs an `os.Exit(1)`. This behavior may be helpful if callers need
489
493
to gracefully shut down. 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.
0 commit comments