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.

Example

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

  is no longer being maintained or added to as of this discussion
  https://github.com/golang/go/issues/13449#issuecomment-161204716

package main

import (
    stdsyslog "log/syslog"

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

func main() {

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

    sysLog.SetFilenameDisplay(log.Llongfile)

    log.RegisterHandler(sysLog, log.AllLevels...)

    // Trace
    defer log.Trace("trace").End()

    log.Debug("debug")
    log.Info("info")
    log.Notice("notice")
    log.Warn("warn")
    log.Error("error")
    // log.Panic("panic") // this will panic
    log.Alert("alert")
    // log.Fatal("fatal") // this will call os.Exit(1)

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

Index

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) DisplayColor Uses

func (s *Syslog) DisplayColor() bool

DisplayColor returns if logging color or not

func (*Syslog) FilenameDisplay Uses

func (s *Syslog) FilenameDisplay() log.FilenameDisplay

FilenameDisplay returns Syslog's current filename display setting

func (*Syslog) GOPATH Uses

func (s *Syslog) GOPATH() string

GOPATH returns the GOPATH calculated by Syslog

func (*Syslog) GetDisplayColor Uses

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

GetDisplayColor returns the color for the given log level

func (*Syslog) Run Uses

func (s *Syslog) Run() chan<- *log.Entry

Run starts the logger consuming on the returned channed

func (*Syslog) SetBuffersAndWorkers Uses

func (s *Syslog) SetBuffersAndWorkers(size uint, workers uint)

SetBuffersAndWorkers sets the channels buffer size and number of concurrent workers. These settings should be thought about together, hence setting both in the same function.

func (*Syslog) SetDisplayColor Uses

func (s *Syslog) SetDisplayColor(color bool)

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

func (*Syslog) SetFilenameDisplay Uses

func (s *Syslog) SetFilenameDisplay(fd log.FilenameDisplay)

SetFilenameDisplay tells Syslog the filename, when present, how to display

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 9 packages (graph) and is imported by 2 packages. Updated 2017-05-22. Refresh now. Tools for package owners.