syslog

package
v6.3.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2018 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

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
    }

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

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

    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.WithField("key", "value").Info("test info")
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FormatFunc

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

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

Formatter is the function used to format the Redis entry

type Syslog

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

Syslog is an instance of the syslog logger

func New

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

func (s *Syslog) DisplayColor() bool

DisplayColor returns if logging color or not

func (*Syslog) GetDisplayColor

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

GetDisplayColor returns the color for the given log level

func (*Syslog) Log

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

Log handles the log entry

func (*Syslog) SetDisplayColor

func (s *Syslog) SetDisplayColor(color bool)

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

func (*Syslog) SetFormatFunc

func (s *Syslog) SetFormatFunc(fn FormatFunc)

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

func (*Syslog) SetTimestampFormat

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

func (s *Syslog) TimestampFormat() string

TimestampFormat returns Syslog's current timestamp output format

Jump to

Keyboard shortcuts

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