slog

package
v0.0.0-...-eb599cc Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debugf

func Debugf(format string, a ...interface{})

Debugf logs with DEBUG severity

func Error

func Error(v interface{})

Error logs with ERROR severity

func Errorf

func Errorf(format string, a ...interface{})

Errorf logs with ERROR severity

func Infof

func Infof(format string, a ...interface{})

Infof logs with INFO severity

func Panic

func Panic(v interface{})

Panic logs with ERROR severity and then panics

func Panicf

func Panicf(format string, a ...interface{})

Panicf logs with ERROR severity and then panics

func Warnf

func Warnf(format string, a ...interface{})

Warnf logs with WARNING severity

Types

type Event

type Event struct {
	Timestamp time.Time
	Severity  Severity
	Message   string
	Metadata  map[string]string
}

Event represents a single log event

func (*Event) String

func (e *Event) String() string

type Logger

type Logger interface {
	Log(*Event)
}

Logger logs logs

var DefaultLogger Logger

DefaultLogger should be used to log all events

func NewStdoutLogger

func NewStdoutLogger() Logger

NewStdoutLogger returns a StdoutLogger for the service with the given name

type Severity

type Severity int

Severity is a subset of the syslog severity levels

const (
	// DebugSeverity is the severity used for debug-level messages
	DebugSeverity Severity = 2

	// InfoSeverity is the severity used for informational messages
	InfoSeverity Severity = 3

	// WarnSeverity is the severity used for warning conditions
	WarnSeverity Severity = 5

	// ErrorSeverity is the severity used for error conditions
	ErrorSeverity Severity = 6

	// UnknownSeverity is the value used when the severity cannot be derived
	UnknownSeverity Severity = 10
)

func (Severity) String

func (s Severity) String() string

String returns the name of the severity level

func (*Severity) UnmarshalJSON

func (s *Severity) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals a JSON string into a Severity

type StdoutLogger

type StdoutLogger struct{}

StdoutLogger writes all logs to stdout

func (*StdoutLogger) Log

func (l *StdoutLogger) Log(event *Event)

Log prints the event to stdout

Jump to

Keyboard shortcuts

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