You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1001 B

  1. package logrus_test
  2. import (
  3. "github.com/sirupsen/logrus"
  4. "gopkg.in/gemnasium/logrus-airbrake-hook.v2"
  5. "os"
  6. )
  7. func Example_hook() {
  8. var log = logrus.New()
  9. log.Formatter = new(logrus.TextFormatter) // default
  10. log.Formatter.(*logrus.TextFormatter).DisableTimestamp = true // remove timestamp from test output
  11. log.Hooks.Add(airbrake.NewHook(123, "xyz", "development"))
  12. log.Out = os.Stdout
  13. log.WithFields(logrus.Fields{
  14. "animal": "walrus",
  15. "size": 10,
  16. }).Info("A group of walrus emerges from the ocean")
  17. log.WithFields(logrus.Fields{
  18. "omg": true,
  19. "number": 122,
  20. }).Warn("The group's number increased tremendously!")
  21. log.WithFields(logrus.Fields{
  22. "omg": true,
  23. "number": 100,
  24. }).Error("The ice breaks!")
  25. // Output:
  26. // level=info msg="A group of walrus emerges from the ocean" animal=walrus size=10
  27. // level=warning msg="The group's number increased tremendously!" number=122 omg=true
  28. // level=error msg="The ice breaks!" number=100 omg=true
  29. }