2017-10-20 09:38:03 +00:00
|
|
|
package syslog
|
2017-06-24 18:25:26 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"log/syslog"
|
|
|
|
"testing"
|
2017-10-20 09:38:03 +00:00
|
|
|
|
|
|
|
"github.com/sirupsen/logrus"
|
2017-06-24 18:25:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestLocalhostAddAndPrint(t *testing.T) {
|
|
|
|
log := logrus.New()
|
|
|
|
hook, err := NewSyslogHook("udp", "localhost:514", syslog.LOG_INFO, "")
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
t.Errorf("Unable to connect to local syslog.")
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Hooks.Add(hook)
|
|
|
|
|
|
|
|
for _, level := range hook.Levels() {
|
|
|
|
if len(log.Hooks[level]) != 1 {
|
|
|
|
t.Errorf("SyslogHook was not added. The length of log.Hooks[%v]: %v", level, len(log.Hooks[level]))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Info("Congratulations!")
|
|
|
|
}
|