syslog

package
v1.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 11, 2021 License: MIT Imports: 5 Imported by: 0

README

Syslog Hooks for Logrus

Usage

import (
  "log/syslog"
  "github.com/aluvare/logrus"
  lSyslog "github.com/aluvare/logrus/hooks/syslog"
)

func main() {
  log       := logrus.New()
  hook, err := lSyslog.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 (
  "log/syslog"
  "github.com/aluvare/logrus"
  lSyslog "github.com/aluvare/logrus/hooks/syslog"
)

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

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

Documentation

Index

Constants

View Source
const (
	NUM_SYSLOG_WORKERS = 8
	CHANNEL_DEPTH      = 8192
)

Variables

This section is empty.

Functions

This section is empty.

Types

type SEntry added in v1.7.1

type SEntry struct {
	// contains filtered or unexported fields
}

type SyslogHook

type SyslogHook struct {
	Writer        *syslog.Writer
	SyslogNetwork string
	SyslogRaddr   string
	Tag           string
	// contains filtered or unexported fields
}

SyslogHook to send logs via syslog.

func NewSyslogHook

func NewSyslogHook(network, raddr string, priority syslog.Priority, tag string) (*SyslogHook, error)

Creates a hook to be added to an instance of logger. This is called with `hook, err := NewSyslogHook("udp", "localhost:514", syslog.LOG_DEBUG, "")` `if err == nil { log.Hooks.Add(hook) }`

func (*SyslogHook) Fire

func (hook *SyslogHook) Fire(entry *logrus.Entry) error

func (*SyslogHook) Levels

func (hook *SyslogHook) Levels() []logrus.Level

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL