log: github.com/go-playground/log/handlers/syslog Index | Files

package syslog

import "github.com/go-playground/log/handlers/syslog"

Package syslog allows for log messages to be sent via syslog.


NOTE: syslog uses github.com/RackSec/srslog as the stdlib syslog

  is no longer being maintained or added to as of this discussion

package main

import (
    stdsyslog "log/syslog"


func main() {

    sysLog, err := syslog.New("udp", "log.logs.com:4863", stdsyslog.LOG_DEBUG, "")
    if err != nil {
        // handle error

    log.AddHandler(sysLog, log.AllLevels...)

    // Trace
    defer log.WithTrace().Info("took this long")

    // log.Panic("panic") // this will panic
    // log.Fatal("fatal") // this will call os.Exit(1)

    // logging with fields can be used with any of the above
    log.WithField("key", "value").Info("test info")


Package Files

doc.go syslog.go

type FormatFunc Uses

type FormatFunc func(s *Syslog) Formatter

FormatFunc is the function that the workers use to create a new Formatter per worker allowing reusable go routine safe variable to be used within your Formatter function.

type Formatter Uses

type Formatter func(e log.Entry) []byte

Formatter is the function used to format the Redis entry

type Syslog Uses

type Syslog struct {
    // contains filtered or unexported fields

Syslog is an instance of the syslog logger

func New Uses

func New(network string, raddr string, tag string, tlsConfig *tls.Config) (*Syslog, error)

New returns a new instance of the syslog logger example: syslog.New("udp", "localhost:514", syslog.LOG_DEBUG, "", nil) NOTE: tlsConfig param is optional and only applies when networks in "tcp+tls" see TestSyslogTLS func tion int syslog_test.go for an example usage of tlsConfig parameter

func (*Syslog) Close Uses

func (s *Syslog) Close() error

Close cleans up any resources and de-registers the handler with the logger

func (*Syslog) DisplayColor Uses

func (s *Syslog) DisplayColor() bool

DisplayColor returns if logging color or not

func (*Syslog) GetDisplayColor Uses

func (s *Syslog) GetDisplayColor(level log.Level) ansi.EscSeq

GetDisplayColor returns the color for the given log level

func (*Syslog) Log Uses

func (s *Syslog) Log(e log.Entry)

Log handles the log entry

func (*Syslog) SetDisplayColor Uses

func (s *Syslog) SetDisplayColor(color bool)

SetDisplayColor tells Syslog to output in color or not Default is : true

func (*Syslog) SetFormatFunc Uses

func (s *Syslog) SetFormatFunc(fn FormatFunc)

SetFormatFunc sets FormatFunc each worker will call to get a Formatter func

func (*Syslog) SetTimestampFormat Uses

func (s *Syslog) SetTimestampFormat(format string)

SetTimestampFormat sets Syslog's timestamp output format Default is : 2006-01-02T15:04:05.000000000Z07:00

func (*Syslog) TimestampFormat Uses

func (s *Syslog) TimestampFormat() string

TimestampFormat returns Syslog's current timestamp output format

Package syslog imports 7 packages (graph) and is imported by 2 packages. Updated 2019-11-12. Refresh now. Tools for package owners.