slog

package module
v2.0.0-alpha.1+incompa... Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2016 License: MIT Imports: 13 Imported by: 0

README

slog

Structured logging for go.

Build Status (Linux)

Usage

Example logging with global logger:

package main

import (
	"errors"
	"github.com/baobabus/slog"
	"time"
)

func emit(i int) error {
	if i % 2 == 0 {
		return errors.New("Bad input")
	}
	return nil
}

func main () {
	slog.Info().Prints("Starting conditional", "time", time.Now())
	for i := 0; i < 4; i++ {
		err := emit(i)
		slog.On(err).Prints("Problem with emit():", "i", i)
	}
	slog.Info().Prints("Finished conditional", "time", time.Now())
	slog.Info().Prints("Starting unconditional", "time", time.Now())
	for i := 0; i < 4; i++ {
		err := emit(i)
		slog.With(err).Prints("Returned from emit():", "i", i)
	}
	slog.Info().Prints("Finished unconditional", "time", time.Now())
}

Output:

INFO 2016/07/20 11:23:58 Starting conditional time=2016-07-20T11:23:58-05:00
ERROR 2016/07/20 11:23:58 Problem with emit(): i=0 - error=Bad input
ERROR 2016/07/20 11:23:58 Problem with emit(): i=2 - error=Bad input
INFO 2016/07/20 11:23:58 Finished conditional time=2016-07-20T11:23:58-05:00
INFO 2016/07/20 11:23:58 Starting unconditional time=2016-07-20T11:23:58-05:00
ERROR 2016/07/20 11:23:58 Returned from emit(): i=0 - error=Bad input
NOTICE 2016/07/20 11:23:58 Returned from emit(): i=1 - success
ERROR 2016/07/20 11:23:58 Returned from emit(): i=2 - error=Bad input
NOTICE 2016/07/20 11:23:58 Returned from emit(): i=3 - success
INFO 2016/07/20 11:23:58 Finished unconditional time=2016-07-20T11:23:58-05:00

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompactJsonFormatter

func CompactJsonFormatter(message string, v []interface{}, e []error) string

func DefaultFilter

func DefaultFilter() []string

func PrettyJsonFormatter

func PrettyJsonFormatter(message string, v []interface{}, e []error) string

func SimpleFormatter

func SimpleFormatter(message string, v []interface{}, es []error) string

Types

type Accessor

type Accessor interface {
	Log(pri Priority) Log
	Info() Log
	Notice() Log
	Warning() Log
	Error() Log
	Trace(detail int) Log
}

type Facility

type Facility interface {
	OpenLogs(level Priority) (map[Priority]*log.Logger, error)
	Reopen() error
}

func NewFileFacility

func NewFileFacility(path string) (Facility, error)

func NewStdFacility

func NewStdFacility(file *os.File) (Facility, error)

func NewSyslogFacility

func NewSyslogFacility(level Priority) (Facility, error)

func SharedFacility

func SharedFacility() Facility

type Formatter

type Formatter func(string, []interface{}, []error) string

func DefaultFormatter

func DefaultFormatter() Formatter

type Log

type Log interface {
	Printe(message string, v ...interface{})
	Prints(message string, v ...interface{})
	Fatals(message string, v ...interface{})
	Logger() *log.Logger
	ScopedLog(err ...error) Log
	Offset(stackOffset int) Log

	// Shortcuts to log.Logger
	Output(calldepth int, s string) error
	Printf(format string, v ...interface{})
	Print(v ...interface{})
	Println(v ...interface{})
	// contains filtered or unexported methods
}

func Error

func Error() Log

func Info

func Info() Log

func Notice

func Notice() Log

func Trace

func Trace(detail int) Log

func Warning

func Warning() Log

type Logger

type Logger interface {
	Accessor
	Level() Priority
	Formatter() Formatter
	On(err ...error) Selector
	Success() Selector
	With(err ...error) Selector
}

func New

func New(facility Facility, level Priority, formatter Formatter, filter []string) (Logger, error)

func SharedLogger

func SharedLogger() Logger

type Priority

type Priority int

Logging level expressed as a number. Positive numbers correspond to trace detail level. Default is value corresponds to Info logging level.

const (
	PriorityError Priority = iota
	PriorityWarn
	PriorityNotice
	PriorityInfo
	PriorityTrace
)

func DefaultLevel

func DefaultLevel() Priority

func (Priority) Bound

func (this Priority) Bound() Priority

func (Priority) SyslogPriority

func (this Priority) SyslogPriority() syslog.Priority

func (Priority) Tag

func (this Priority) Tag() string

type Selector

type Selector interface {
	Accessor
	Prints(message string, v ...interface{})
	Fatals(message string, v ...interface{})
	Logger() *log.Logger
}

func On

func On(err ...error) Selector

func Success

func Success() Selector

func With

func With(err ...error) Selector

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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