logger

package
v0.0.0-...-ef901e4 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CatServer is server lifecycle log
	CatServer Category = "server"
	// CatLogger is logging system events
	CatLogger = "logger"
	// CatTracing is tracing system events
	CatTracing = "tracing"
	// CatAuth is auth related events
	CatAuth = "auth"
	// CatHTTP is HTTP layer log
	CatHTTP = "http"
	// CatStorage is storage events
	CatStorage = "storage"
	// CatOutgoingWebhook is outgoing webhook events
	CatOutgoingWebhook = "webhook-out"
)

Variables

This section is empty.

Functions

func PinLoggerContext

func PinLoggerContext(ctx context.Context) context.Context

PinLoggerContext creates context-specific logger along with the new context. By default, logger.Of(Context) returns same logger instance if no configuration changed. Some operation (e.g. global handlers) looks top-most context that logger belongs to.

func SetGlobalErrorHandler

func SetGlobalErrorHandler(f ErrorHandler)

SetGlobalErrorHandler to set callback function for each error log

func WithTestLogger

func WithTestLogger(t *testing.T, filter *Filter, f func(lc *LogCapture))

WithTestLogger swaps global logger for testing only.

Types

type CapturedLog

type CapturedLog struct {
	zapcore.Entry
	Fields []zapcore.Field
}

CapturedLog represents captured log object

func (CapturedLog) FindErrorField

func (log CapturedLog) FindErrorField() error

FindErrorField returns error field of the log or nil

func (CapturedLog) FindStringField

func (log CapturedLog) FindStringField(key string) string

FindStringField string field of the given name

type Category

type Category string

Category of logs

func ParseCategory

func ParseCategory(str string) Category

ParseCategory make category string

type ContextLoggerBuilder

type ContextLoggerBuilder interface {
	Build() context.Context

	WithStr(key string, value string) ContextLoggerBuilder
	WithInt(key string, value int) ContextLoggerBuilder
	WithInt64(key string, value int64) ContextLoggerBuilder
	WithBool(key string, value bool) ContextLoggerBuilder
}

ContextLoggerBuilder is an interface to create child context that holds child logger

func WithAttributes

func WithAttributes(ctx context.Context) ContextLoggerBuilder

WithAttributes returns builder to create child context that holds child logger

type ErrorHandler

type ErrorHandler func(ctx context.Context, msg string, err error)

ErrorHandler function to receive error logs

type Filter

type Filter struct {
	// contains filtered or unexported fields
}

Filter controls log verbosity

func InitLogger

func InitLogger(config *config.LoggingConfig) (*Filter, error)

InitLogger initializes Logger

func NewFilter

func NewFilter(thresholds map[string]string) (*Filter, error)

NewFilter creates Filter instance with given thresholds configuration.

func (*Filter) Filter

func (filter *Filter) Filter(level Level, cat Category) bool

Filter determines whether to output (true) the log or not (false).

func (*Filter) SetThreshold

func (filter *Filter) SetThreshold(cat Category, level Level)

SetThreshold changes threshold immediately

type Level

type Level int

Level represents log severity. Larger value represents more important log.

const (
	// DEBUG log level
	DEBUG Level = iota
	// INFO log level
	INFO
	// WARN log level
	WARN
	// ERROR log level
	ERROR
	// FATAL log level
	FATAL
)

func ParseLevel

func ParseLevel(str string) (Level, error)

ParseLevel parses log level string

func (Level) String

func (level Level) String() string

type LogCapture

type LogCapture struct {
	// contains filtered or unexported fields
}

LogCapture represents log capture system for testing purpose

func (*LogCapture) Count

func (c *LogCapture) Count() int

Count returns total count of captured logs

func (*LogCapture) LastLog

func (c *LogCapture) LastLog(offset int) *CapturedLog

LastLog returns captured log

type Logger

type Logger interface {
	// output fatal log then exit this process immediately
	FatalExitProcess(msg string, err error)

	Error(msg string, err error)
	WarnError(cat Category, msg string, err error)
	InfoError(cat Category, msg string, err error)

	Warnf(cat Category, template string, args ...interface{})
	Infof(cat Category, template string, args ...interface{})
	Debugf(cat Category, template string, args ...interface{})
}

Logger represents implementation independent logger, also easy to inject mock.

func Of

func Of(ctx context.Context) Logger

Of returns or creates Logger instance associated to the context.

Jump to

Keyboard shortcuts

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