slog

package module
v0.0.0-...-4302b45 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2016 License: MIT Imports: 9 Imported by: 3

README

slog

Structured logging.

slog is a library for capturing structured log information. In contrast to "traditional" logging libraries, slog:

  • captures a Context for each logging event
  • captures arbitrary key-value metadata on each log event

Currently, slog forwards messages to seelog by default. However, it is easy to write customised outputs which make use of the context and metadata.

At Mondo, slog captures events both on a per-service and a per-request basis (using the context information). This lets us view all the logs for a given request across all the micro-services it touches.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Critical

func Critical(ctx context.Context, msg string, params ...interface{})

Critical constructs a logging event with critical severity, and sends it via the default Logger

func Debug

func Debug(ctx context.Context, msg string, params ...interface{})

Debug constructs a logging event with debug severity, and sends it via the default Logger

func Error

func Error(ctx context.Context, msg string, params ...interface{})

Critical constructs a logging event with error severity, and sends it via the default Logger

func Info

func Info(ctx context.Context, msg string, params ...interface{})

Info constructs a logging event with info severity, and sends it via the default Logger

func Log

func Log(evs ...Event)

Log sends the given Events via the default Logger

func SetDefaultLogger

func SetDefaultLogger(l Logger)

func Trace

func Trace(ctx context.Context, msg string, params ...interface{})

Trace constructs a logging event with trace severity, and sends it via the default Logger

func Warn

func Warn(ctx context.Context, msg string, params ...interface{})

Warn constructs a logging event with warn severity, and sends it via the default Logger

Types

type Event

type Event struct {
	Context   context.Context `json:"-"`
	Id        string          `json:"id"`
	Timestamp time.Time       `json:"timestamp"`
	Severity  Severity        `json:"severity"`
	Message   string          `json:"message"`
	// Metadata are structured key-value pairs which describe the event.
	Metadata map[string]string `json:"meta,omitempty"`
	// Labels, like Metadata, are key-value pairs which describe the event. Unlike Metadata, these are intended to be
	// indexed.
	Labels map[string]string `json:"labels,omitempty"`
}

An Event is a discrete logging event

func Eventf

func Eventf(sev Severity, ctx context.Context, msg string, params ...interface{}) Event

Eventf constructs an event from the given message string and formatting operands. Optionally, event metadata (map[string]string) can be provided as a final argument.

func (Event) String

func (e Event) String() string

type EventSet

type EventSet []Event

EventSet is a time-sortable collection of logging events.

func (EventSet) Len

func (es EventSet) Len() int

func (EventSet) Less

func (es EventSet) Less(i, j int) bool

func (EventSet) String

func (es EventSet) String() string

func (EventSet) Swap

func (es EventSet) Swap(i, j int)

type Logger

type Logger interface {
	Log(evs ...Event)
	Flush() error
}

A Logger is a way of outputting events.

func DefaultLogger

func DefaultLogger() Logger

func SeelogLogger

func SeelogLogger() Logger

type MultiLogger

type MultiLogger []Logger

A MultiLogger sends invocations to multiple Loggers.

func (MultiLogger) Flush

func (ls MultiLogger) Flush() error

func (MultiLogger) Log

func (ls MultiLogger) Log(evs ...Event)

type Severity

type Severity int
const (
	TimeFormat             = "2006-01-02 15:04:05-0700 (MST)"
	TraceSeverity Severity = iota
	DebugSeverity
	InfoSeverity
	WarnSeverity
	ErrorSeverity
	CriticalSeverity
)

func (Severity) String

func (s Severity) String() string

Jump to

Keyboard shortcuts

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