sysloghook

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2018 License: MIT Imports: 3 Imported by: 0

README

Syslog Hooks for Logrus

Forked from github.com/sirupsen/logrus, just added a formatting option

Usage
import (
  "log/syslog"
  "github.com/sirupsen/logrus"
  "github.com/fkmeland/go-logrus-sysloghook"
)

func main() {
  log       := logrus.New()
  hook, err := sysloghook.NewSyslogHook("udp", "localhost:514", syslog.LOG_INFO, "",  &logrus.TextFormatter {
 	DisableTimestamp: true,
  })

  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/sirupsen/logrus"
  "github.com/fkmeland/go-logrus-sysloghook"
)

func main() {
  log       := logrus.New()
  hook, err := sysloghook.NewSyslogHook("", "", syslog.LOG_INFO, "", &logrus.TextFormatter {
 	DisableTimestamp: true,
  })

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SyslogHook

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

SyslogHook to send logs via syslog.

func NewSyslogHook

func NewSyslogHook(network, raddr string, priority syslog.Priority, tag string, formatter logrus.Formatter) (*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

func (*SyslogHook) SetFormatter

func (hook *SyslogHook) SetFormatter(formatter logrus.Formatter)

SetFormatter sets the format that will be used by hook. If using text formatter, this method will disable color output to make the log file more readable.

Jump to

Keyboard shortcuts

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