logger

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: MIT Imports: 14 Imported by: 5

Documentation

Index

Constants

View Source
const (

	// We repeat this constant here as we don't want the circular dependency
	// of importint our tracing package
	TraceIDKey = "x-b3-traceid"
)

Variables

View Source
var (
	Plain *zap.Logger
	Sugar *WrappedLogger

	Recorded *observer.ObservedLogs
)

Functions

func New

func New(level string, opts ...any)

New creates 2 loggers (plain and sugared) as global variables according to the desired loglevel ("DEBUG", "NOOP", "TEST", default is "INFO"). Additionally log output from other loggers in 3rd-party packages is redirected to the INFO label of these loggers. Both ResourceOption and zap.Option types are supported option types. The zap.Options are passed on the to zap logger.

func OnExit

func OnExit()

OnExit should be deferred immediately after calling the New() method.

Types

type Logger

type Logger interface {
	Debugf(string, ...any)
	DebugR(string, ...any)

	Infof(string, ...any)
	InfoR(string, ...any)

	Panicf(string, ...any)

	FromContext(context.Context) *WrappedLogger
	WithIndex(string, string) *WrappedLogger
	WithServiceName(string) *WrappedLogger
	Close()

	WithOptions(...Option) *WrappedLogger
}

type Option

type Option = zap.Option

so we dont have to import zap everywhere

type Resource

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

Resource - the counter is initialised with a zero value which indicates that the uber correction is made (default).

type ResourceOption

type ResourceOption func(*Resource)

func WithConsole

func WithConsole() ResourceOption

func WithFile

func WithFile(filename string) ResourceOption

type Syncer

type Syncer func() error

type WrappedLogger

type WrappedLogger struct {
	*zap.SugaredLogger
}

func (*WrappedLogger) Close

func (wl *WrappedLogger) Close()

Close attempts to flush any buffered log entries.

func (*WrappedLogger) DebugR

func (l *WrappedLogger) DebugR(msg string, args ...any)

func (*WrappedLogger) ErrorR

func (l *WrappedLogger) ErrorR(msg string, args ...any)

func (*WrappedLogger) FromContext

func (wl *WrappedLogger) FromContext(ctx context.Context) *WrappedLogger

FromContext takes the trace ID from the current span and adds it to a child wrapped logger:

returns:

  • the new wrapped logger with a context metadata value for traceID

This will be called on entry to a method or a function that has a context.Context.

func (*WrappedLogger) InfoR

func (l *WrappedLogger) InfoR(msg string, args ...any)

func (*WrappedLogger) WithIndex

func (wl *WrappedLogger) WithIndex(key, value string) *WrappedLogger

func (*WrappedLogger) WithOptions

func (wl *WrappedLogger) WithOptions(opts ...Option) *WrappedLogger

func (*WrappedLogger) WithServiceName

func (wl *WrappedLogger) WithServiceName(servicename string) *WrappedLogger

Jump to

Keyboard shortcuts

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