syslog

package
v0.1.20 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2020 License: MIT Imports: 5 Imported by: 0

README

Syslog Hooks

Usage

import (
    "log/syslog"
    "github.com/bdlm/log"
    "github.com/bdlm/log/hooks/syslog"
)

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

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

If you want to connect to the local syslog (Ex. /dev/log or /var/run/syslog or /var/run/log), simply pass an empty string to the first two parameters of NewSyslogHook. For example:

import (
    "log/syslog"
    "github.com/bdlm/log"
    syslog "github.com/bdlm/log/hooks/syslog"
)

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

    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 Hook added in v0.1.2

type Hook struct {
	Writer        *syslog.Writer
	SyslogNetwork string
	SyslogRaddr   string
}

Hook to send logs via syslog.

func NewHook added in v0.1.2

func NewHook(network, raddr string, priority syslog.Priority, tag string) (*Hook, error)

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

func (*Hook) Fire added in v0.1.2

func (hook *Hook) Fire(entry *log.Entry) error

Fire executes the syslog hook.

func (*Hook) Levels added in v0.1.2

func (hook *Hook) Levels() []stdLogger.Level

Levels returns all available log levels.

Jump to

Keyboard shortcuts

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