log

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DebugInterface func(args ...interface{})
View Source
var Debugf func(template string, args ...interface{})
View Source
var Debugw func(msg string, keysAndValues ...interface{})
View Source
var Error func(err error)
View Source
var ErrorInterface func(args ...interface{})
View Source
var Errorf func(template string, args ...interface{})
View Source
var Errorw func(msg string, keysAndValues ...interface{})
View Source
var Fatal func(err error)
View Source
var FatalInterface func(args ...interface{})
View Source
var Fatalf func(template string, args ...interface{})
View Source
var Fatalw func(msg string, keysAndValues ...interface{})
View Source
var InfoInterface func(args ...interface{})
View Source
var Infof func(template string, args ...interface{})
View Source
var Infow func(msg string, keysAndValues ...interface{})
View Source
var Panic func(err error)
View Source
var PanicInterface func(args ...interface{})
View Source
var Panicf func(template string, args ...interface{})
View Source
var Panicw func(msg string, keysAndValues ...interface{})
View Source
var WarnInterface func(args ...interface{})
View Source
var Warnf func(template string, args ...interface{})
View Source
var Warnw func(msg string, keysAndValues ...interface{})
View Source
var With func(args ...interface{}) Logger
View Source
var WithError func(err error) Logger
View Source
var WithOptions func(opts ...zap.Option) Logger
View Source
var WithStackTrace func(stack stackerr.Stack, useAsCaller bool) Logger

Functions

func DeregisterDefaultWriteHook

func DeregisterDefaultWriteHook(key string) stackerr.Error

func GetAwsLogger

func GetAwsLogger() logging.Logger

func InitDefault

func InitDefault(input NewInput) stackerr.Error

InitDefault will create a new logger with the given settings and will set it as the default global logger. This function IS NOT thread-safe and cannot be used while other routines are using the existing global default logger.

func LogContext

func LogContext(ctx context.Context, logger Logger) context.Context

LogContext will return a new context with the given logger added to the given context.

func RegisterDefaultWriteHook

func RegisterDefaultWriteHook(key string, hook ZapWriteHook) stackerr.Error

func SweetenDefaultLogger

func SweetenDefaultLogger(fields map[string]any) stackerr.Error

SweetenDefaultLogger will add fields to the default logger.

func SweetenDefaultLoggerForLambda

func SweetenDefaultLoggerForLambda(ctx context.Context, fields map[string]any) stackerr.Error

SweetenDefaultLoggerForLambda will add Lambda metadata fields (request ID and logs URL) to the default logger, as well as any additional fields in the `fields` parameter. If this is not executed within a Lambda function, nothing will be added.

func UnsweetenDefaultLogger

func UnsweetenDefaultLogger(fieldKeys []string) stackerr.Error

UnsweetenDefaultLogger will remove fields from the default logger.

Types

type DynamicDefaultLogger

type DynamicDefaultLogger interface {
	Logger() Logger
	IsDevelopment() bool
	Close()
}

func NewDynamicDefaultLogger

func NewDynamicDefaultLogger(loggerConfigFunc func(input NewInput) NewInput) DynamicDefaultLogger

type Logger

type Logger interface {
	Debugf(template string, args ...interface{})
	Infof(template string, args ...interface{})
	Warnf(template string, args ...interface{})
	Errorf(template string, args ...interface{})
	Fatalf(template string, args ...interface{})
	Panicf(template string, args ...interface{})

	Debugw(msg string, keysAndValues ...interface{})
	Infow(msg string, keysAndValues ...interface{})
	Warnw(msg string, keysAndValues ...interface{})
	Errorw(msg string, keysAndValues ...interface{})
	Fatalw(msg string, keysAndValues ...interface{})
	Panicw(msg string, keysAndValues ...interface{})

	DebugInterface(args ...interface{})
	InfoInterface(args ...interface{})
	WarnInterface(args ...interface{})
	ErrorInterface(args ...interface{})
	FatalInterface(args ...interface{})
	PanicInterface(args ...interface{})

	Error(err error)
	Panic(err error)
	Fatal(err error)

	With(args ...interface{}) Logger
	WithOptions(opts ...zap.Option) Logger
	WithError(err error) Logger
	WithStackTrace(stack stackerr.Stack, useAsCaller bool) Logger

	// WithAdditionalSkippedFrames will return a new logger that skips additional
	// frames when finding the caller and the stack trace.
	WithAdditionalSkippedFrames(skippedFrames int) Logger

	// RegisterWriteHook will register a function hook that will be called
	// for each log write.
	RegisterWriteHook(key string, hook ZapWriteHook) stackerr.Error

	// DergisterWriteHook will deregister a hook that was registered with RegisterWriteHook
	DergisterWriteHook(key string) stackerr.Error

	// Config gets the config values that can be used to re-create this logger
	Config() NewInput

	// Clone returns a copy of the logger
	Clone() Logger
}

func FromContext

func FromContext(ctx context.Context) Logger

FromContext will extract a logger from a context if it contains one, or return the default logger if it doesn't.

func New

func New(input NewInput) Logger

type NewInput

type NewInput struct {
	Name          string
	Level         zapcore.Level
	IsDevelopment bool
	WriteHooks    map[string]ZapWriteHook
	InitialFields map[string]any
	SkippedFrames int
}

func (*NewInput) Clone

func (ni *NewInput) Clone() NewInput

type StackError

type StackError struct {
	Key         string          `json:"key,omitempty"`
	Fields      map[string]any  `json:"fields,omitempty"`
	Message     string          `json:"message,omitempty"`
	Stacktraces stackerr.Stacks `json:"stacktraces,omitempty"`
}

type ZapWriteHook

type ZapWriteHook func(e zapcore.Entry, logFields map[string]zapcore.Field, errs []StackError, stacktraces stackerr.Stacks) stackerr.Error

Jump to

Keyboard shortcuts

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