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.

27 lines
533 B

  1. package syslog
  2. import (
  3. "log/syslog"
  4. "testing"
  5. "github.com/sirupsen/logrus"
  6. )
  7. func TestLocalhostAddAndPrint(t *testing.T) {
  8. log := logrus.New()
  9. hook, err := NewSyslogHook("udp", "localhost:514", syslog.LOG_INFO, "")
  10. if err != nil {
  11. t.Errorf("Unable to connect to local syslog.")
  12. }
  13. log.Hooks.Add(hook)
  14. for _, level := range hook.Levels() {
  15. if len(log.Hooks[level]) != 1 {
  16. t.Errorf("SyslogHook was not added. The length of log.Hooks[%v]: %v", level, len(log.Hooks[level]))
  17. }
  18. }
  19. log.Info("Congratulations!")
  20. }