logger

package
v2.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2020 License: Apache-2.0 Imports: 7 Imported by: 1,015

Documentation

Overview

Package log provides a log interface

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug added in v2.1.1

func Debug(args ...interface{})

func Debugf added in v2.1.1

func Debugf(template string, args ...interface{})

func Error added in v2.1.1

func Error(args ...interface{})

func Errorf added in v2.1.1

func Errorf(template string, args ...interface{})

func Fatal added in v2.1.1

func Fatal(args ...interface{})

func Fatalf added in v2.1.1

func Fatalf(template string, args ...interface{})

func Info added in v2.1.1

func Info(args ...interface{})

func Infof added in v2.1.1

func Infof(template string, args ...interface{})

func Init added in v2.1.1

func Init(opts ...Option) error

func Log added in v2.1.1

func Log(level Level, v ...interface{})

func Logf added in v2.1.1

func Logf(level Level, format string, v ...interface{})

func NewContext

func NewContext(ctx context.Context, l Logger) context.Context

func String added in v2.1.1

func String() string

func Trace added in v2.1.1

func Trace(args ...interface{})

func Tracef added in v2.1.1

func Tracef(template string, args ...interface{})

func Warn added in v2.1.1

func Warn(args ...interface{})

func Warnf added in v2.1.1

func Warnf(template string, args ...interface{})

Types

type Level

type Level int8
const (
	// TraceLevel level. Designates finer-grained informational events than the Debug.
	TraceLevel Level = iota - 2
	// DebugLevel level. Usually only enabled when debugging. Very verbose logging.
	DebugLevel
	// InfoLevel is the default logging priority.
	// General operational entries about what's going on inside the application.
	InfoLevel
	// WarnLevel level. Non-critical entries that deserve eyes.
	WarnLevel
	// ErrorLevel level. Logs. Used for errors that should definitely be noted.
	ErrorLevel
	// PanicLevel level, logs the message and then panics.
	PanicLevel
	// FatalLevel level. Logs and then calls `logger.Exit(1)`. highest level of severity.
	FatalLevel
)

func GetLevel added in v2.1.1

func GetLevel(levelStr string) (Level, error)

GetLevel converts a level string into a logger Level value. returns an error if the input string does not match known values.

func (Level) Enabled added in v2.1.1

func (l Level) Enabled(lvl Level) bool

Enabled returns true if the given level is at or above this level.

func (Level) String added in v2.1.1

func (l Level) String() string

type Logger

type Logger interface {
	// Init initialises options
	Init(options ...Option) error
	// The Logger options
	Options() Options
	// Error set `error` field to be logged
	Error(err error) Logger
	// Fields set fields to always be logged
	Fields(fields map[string]interface{}) Logger
	// Log writes a log entry
	Log(level Level, v ...interface{})
	// Logf writes a formatted log entry
	Logf(level Level, format string, v ...interface{})
	// String returns the name of logger
	String() string
}

Logger is a generic logging interface

var (
	// Default logger
	DefaultLogger Logger = NewLogger()
)

func Fields added in v2.1.1

func Fields(fields map[string]interface{}) Logger

func FromContext

func FromContext(ctx context.Context) (Logger, bool)

func NewLogger added in v2.1.1

func NewLogger(opts ...Option) Logger

NewLogger builds a new logger based on options

func WithError added in v2.1.1

func WithError(err error) Logger

type Option

type Option func(*Options)

func SetOption added in v2.1.1

func SetOption(k, v interface{}) Option

func WithFields added in v2.1.1

func WithFields(fields map[string]interface{}) Option

WithFields set default fields for the logger

func WithLevel added in v2.1.1

func WithLevel(level Level) Option

WithLevel set default level for the logger

func WithOutput added in v2.1.1

func WithOutput(out io.Writer) Option

WithOutput set default output writer for the logger

type Options

type Options struct {
	// The logging level the logger should log at. default is `InfoLevel`
	Level Level
	// fields to always be logged
	Fields map[string]interface{}
	// It's common to set this to a file, or leave it default which is `os.Stderr`
	Out io.Writer
	// Alternative options
	Context context.Context
}

Jump to

Keyboard shortcuts

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