slog

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2020 License: MIT Imports: 14 Imported by: 0

README

slog GoDoc

slog is an opinionated structured logging implementation.

Documentation

Overview

Pulled from the github.com/oxtoacart/bpool

Index

Constants

This section is empty.

Variables

View Source
var (
	// Writer is the writer interface which the logs will be written too.
	Writer = NewLockedWriteSyncer(os.Stdout)

	// TimeStampKey is the json key for the timestamp output.
	TimeStampKey = "ts"

	// EnableDebug will print debug logs if true.
	EnableDebug = false

	// RequestToken is the token generator for the request middleware.
	RequestToken Token = &genericToken{}
)
View Source
var (
	// RequestHeaderKey is the key used when adding the header token.
	RequestHeaderKey = "___slog_request_token___"

	// RequestFieldKey is the key used in the Field output.
	RequestFieldKey = "reqID"

	// ResponseHeaderKey will send the token on the response as well (if set).
	ResponseHeaderKey = ""
)
View Source
var DiscardWrapper = &noSyncWrapper{ioutil.Discard}

DiscardWrapper is used for testing.

Functions

func Debug

func Debug(message string, fields ...Field)

func Error

func Error(message string, fields ...Field)

func Fatal

func Fatal(message string, fields ...Field)

func Info

func Info(message string, fields ...Field)

func Panic

func Panic(message string, fields ...Field)

func Requestify

func Requestify(next http.Handler) http.Handler

Requestify adds a unique key to the request (header) and uses it for logging.

func Warning

func Warning(message string, fields ...Field)

Types

type Field

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

func Bool

func Bool(key string, val bool) Field

func Duration

func Duration(key string, val time.Duration) Field

func Err

func Err(err error) Field

func Float64

func Float64(key string, val float64) Field

func Int

func Int(key string, val int) Field

func Int64

func Int64(key string, val int64) Field

func NullableString

func NullableString(key string, val string) Field

func Request

func Request(r *http.Request) Field

func Skip

func Skip() Field

func String

func String(key string, val string) Field

func Time

func Time(key string, val time.Time) Field

func Uint

func Uint(key string, val uint) Field

func Uint64

func Uint64(key string, val uint64) Field

func Uintptr

func Uintptr(key string, val uintptr) Field

type LockedSyslogWriteSyncer

type LockedSyslogWriteSyncer struct {
	sync.Mutex
	// contains filtered or unexported fields
}

LockedSyslogWriteSyncer logs to syslog as well as stdout.

func (*LockedSyslogWriteSyncer) Sync

func (l *LockedSyslogWriteSyncer) Sync() error

func (*LockedSyslogWriteSyncer) Write

func (l *LockedSyslogWriteSyncer) Write(bs []byte) (int, error)

type LogFunc

type LogFunc func(message string, fields ...Field)

type Token

type Token interface {
	Generate() string
}

Token is an interface for generating tokens for the middleware.

type WriteSyncer

type WriteSyncer interface {
	io.Writer
	Sync() error
}

A WriteSyncer is an io.Writer that can also flush any buffered data. Note that *os.File (and thus, os.Stderr and os.Stdout) implement WriteSyncer.

func NewDatadogLockedSyslogWriteSyncer

func NewDatadogLockedSyslogWriteSyncer(network, address, tag, key string) WriteSyncer

NewDatadogLockedSyslogWriteSyncer creates a new write syncer for datadog syslog.

func NewLockedSyslogWriteSyncer

func NewLockedSyslogWriteSyncer(network, address, tag string) WriteSyncer

NewLockedSyslogWriteSyncer creates a new write syncer for syslog.

func NewLockedWriteSyncer

func NewLockedWriteSyncer(ws WriteSyncer) WriteSyncer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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