logger

package
v0.0.0-...-31becf5 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2021 License: Apache-2.0 Imports: 12 Imported by: 2

Documentation

Overview

Package logger provides a log interface

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(args ...interface{})

Debug Log writes a log entry

func Debugf

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

Debugf Log writes a log entry

func Error

func Error(args ...interface{})

Error Log writes a log entry

func Errorf

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

Errorf Log writes a log entry

func Fatal

func Fatal(args ...interface{})

Fatal Log writes a log entry

func Fatalf

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

Fatalf Log writes a log entry

func Info

func Info(args ...interface{})

Info Log writes a log entry

func Infof

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

Infof Log writes a log entry

func Init

func Init(opts ...Option) error

Init init default logger

func Level

func Level() level.Level

Level return logger Level

func Log

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

Log writes a log entry

func Logf

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

Logf writes a log entry

func Trace

func Trace(args ...interface{})

Trace Log writes a log entry

func Tracef

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

Tracef Log writes a log entry

func V

func V(lvl level.Level, log Logger) bool

V Returns true if the given Level is at or lower the current logger Level

func Warn

func Warn(args ...interface{})

Warn Log writes a log entry

func Warnf

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

Warnf Log writes a log entry

Types

type Helper

type Helper struct {
	Logger
	// contains filtered or unexported fields
}

func NewHelper

func NewHelper(log Logger) *Helper

func (*Helper) Debug

func (h *Helper) Debug(args ...interface{})

func (*Helper) Debugf

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

func (*Helper) Error

func (h *Helper) Error(args ...interface{})

func (*Helper) Errorf

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

func (*Helper) Fatal

func (h *Helper) Fatal(args ...interface{})

func (*Helper) Fatalf

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

func (*Helper) Info

func (h *Helper) Info(args ...interface{})

func (*Helper) Infof

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

func (*Helper) Trace

func (h *Helper) Trace(args ...interface{})

func (*Helper) Tracef

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

func (*Helper) Warn

func (h *Helper) Warn(args ...interface{})

func (*Helper) Warnf

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

func (*Helper) WithError

func (h *Helper) WithError(err error) *Helper

func (*Helper) WithFields

func (h *Helper) WithFields(fields map[string]interface{}) *Helper

type Logger

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

Logger is a generic logging interface

var (
	// DefaultLogger logger
	DefaultLogger Logger
)

func NewLogger

func NewLogger(opts ...Option) Logger

NewLogger builds a new logger based on Options

type Option

type Option func(*Options)

Option set Options

func SetOption

func SetOption(k, v interface{}) Option

SetOption set option

func WithCallerSkipCount

func WithCallerSkipCount(c int) Option

WithCallerSkipCount set frame count to skip

func WithFields

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

WithFields set default Fields for the logger

func WithLevel

func WithLevel(level level.Level) Option

WithLevel set default Level for the logger

func WithName

func WithName(name string) Option

WithName set Name for logger

func WithOutput

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.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
	// Caller skip frame count for file:line info
	CallerSkipCount int
	// Alternative Options
	Context context.Context
	// Name logger Name
	Name string
}

Options options

Directories

Path Synopsis
Package formatter provides debug logging
Package formatter provides debug logging

Jump to

Keyboard shortcuts

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