Skip to content

shinji62/logrus-syslog-ng

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Syslog Hooks for Logrus supporting TLS :walrus:

Description

Simple drop-in replacement for the default hook for syslog.

Adding support for TLS and using https://github.com/RackSec/srslog instead of go default log/syslog lib.

Usage for tls

Only tcp+tls protocol is supported in this case

import (
  syslog "github.com/RackSec/srslog"
  "github.com/Sirupsen/logrus"
  logrus_syslog "github.com/shinji62/logrus-syslog-ng"
)

func main() {
  log       := logrus.New()
  hook, err := logrus_syslog.NewSyslogHookTLS("localhost:514", syslog.LOG_INFO, "tag","./mycert.pem")

  if err == nil {
    log.Hooks.Add(hook)
  }
}

Usage without TLS

Tcp, udp are supported

import (
  syslog "github.com/RackSec/srslog"
  "github.com/Sirupsen/logrus"
  logrus_syslog "github.com/shinji62/logrus-syslog-ng"
)

func main() {
  log       := logrus.New()
  hook, err := logrus_syslog.NewSyslogHook("udp", "localhost:514", syslog.LOG_INFO, "")

  if err == nil {
    log.Hooks.Add(hook)
  }
}

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.

import (
  syslog "github.com/RackSec/srslog"
  "github.com/Sirupsen/logrus"
  logrus_syslog "github.com/shinji62/logrus-syslog-ng"
)

func main() {
  log       := logrus.New()
  hook, err := logrus_syslog.NewSyslogHook("", "", syslog.LOG_INFO, "")

  if err == nil {
    log.Hooks.Add(hook)
  }
}

About

Syslog hook supporting TLS and retry

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages