...

Source file src/github.com/sirupsen/logrus/hooks/syslog/syslog_test.go

Documentation: github.com/sirupsen/logrus/hooks/syslog

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

View as plain text