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.

39 lines
926 B

  1. # Syslog Hooks for Logrus <img src="http://i.imgur.com/hTeVwmJ.png" width="40" height="40" alt=":walrus:" class="emoji" title=":walrus:"/>
  2. ## Usage
  3. ```go
  4. import (
  5. "log/syslog"
  6. "github.com/sirupsen/logrus"
  7. lSyslog "github.com/sirupsen/logrus/hooks/syslog"
  8. )
  9. func main() {
  10. log := logrus.New()
  11. hook, err := lSyslog.NewSyslogHook("udp", "localhost:514", syslog.LOG_INFO, "")
  12. if err == nil {
  13. log.Hooks.Add(hook)
  14. }
  15. }
  16. ```
  17. If you want to connect to local syslog (Ex. "/dev/log" or "/var/run/syslog" or "/var/run/log"). Just assign empty string to the first two parameters of `NewSyslogHook`. It should look like the following.
  18. ```go
  19. import (
  20. "log/syslog"
  21. "github.com/sirupsen/logrus"
  22. lSyslog "github.com/sirupsen/logrus/hooks/syslog"
  23. )
  24. func main() {
  25. log := logrus.New()
  26. hook, err := lSyslog.NewSyslogHook("", "", syslog.LOG_INFO, "")
  27. if err == nil {
  28. log.Hooks.Add(hook)
  29. }
  30. }
  31. ```