logger

package
v0.0.0-...-aa6650d Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: Apache-2.0, BSD-2-Clause-Views, BSD-3-Clause, + 1 more Imports: 15 Imported by: 49

Documentation

Index

Constants

View Source
const (
	RequestIdHeader = "X-Vcap-Request-Id"
)

Variables

This section is empty.

Functions

func CreateLogger

func CreateLogger() *slog.Logger

CreateLogger returns a copy of the logger. All subsequent log statements will be nested in the 'data' field.

func CreateLoggerWithSource

func CreateLoggerWithSource(prefix string, component string) *slog.Logger

CreateLoggerWithSource returns a copy of the logger, which comes with the 'source' attribute set to the provided prefix and component. All subsequent log statements will be nested in the 'data' field.

func ErrAttr

func ErrAttr(err error) slog.Attr

ErrAttr is creating an slog.String attribute with 'error' key and the provided error message as value.

func Fatal

func Fatal(logger *slog.Logger, message string, slogAttrs ...any)

Fatal logs message and slogAttrs with Error level. For compatibility with zlog, the process is terminated via os.Exit(1) after writing the log message.

func Panic

func Panic(logger *slog.Logger, message string, slogAttrs ...any)

Panic logs message and slogAttrs with Error level. For compatibility with zlog, the function is panicking after writing the log message.

func RFC3339Formatter

func RFC3339Formatter() zapcore.TimeEncoder

RFC3339Formatter TimeEncoder for RFC3339 with trailing Z for UTC and nanoseconds

func SetDynamicWriteSyncer

func SetDynamicWriteSyncer(syncer WriteSyncer)

SetDynamicWriteSyncer sets the log handler's sink.

func SetLoggingLevel

func SetLoggingLevel(level string)

SetLoggingLevel dynamically sets the logging level at runtime. See https://github.com/uber-go/zap/blob/5786471c1d41c255c1d8b63ad30a82b68eda2c21/zapcore/level.go#L180 for possible logging levels.

func SetTimeEncoder

func SetTimeEncoder(enc string)

SetTimeEncoder dynamically sets the time encoder at runtime: 'rfc3339': The encoder is set to a custom RFC3339 encoder All other values: The encoder is set to an Epoch encoder

Types

type LagerAdapter

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

LagerAdapter tbd

func NewLagerAdapter

func NewLagerAdapter(source string) *LagerAdapter

NewLagerAdapter returns a new lager.Logger that uses slog with a zap handler underneath.

func (*LagerAdapter) Debug

func (l *LagerAdapter) Debug(action string, data ...lager.Data)

Debug logs a message at the debug log setLoggingLevel.

func (*LagerAdapter) Error

func (l *LagerAdapter) Error(action string, err error, data ...lager.Data)

Error logs a message at the error log setLoggingLevel.

func (*LagerAdapter) Fatal

func (l *LagerAdapter) Fatal(action string, err error, data ...lager.Data)

Fatal logs a message and exits with status 1.

func (*LagerAdapter) Info

func (l *LagerAdapter) Info(action string, data ...lager.Data)

Info logs a message at the info log setLoggingLevel.

func (*LagerAdapter) RegisterSink

func (l *LagerAdapter) RegisterSink(_ lager.Sink)

RegisterSink is never used after initialization, so it does nothing.

func (*LagerAdapter) Session

func (l *LagerAdapter) Session(task string, data ...lager.Data) lager.Logger

Session returns a new logger with a nested source and optional data.

func (*LagerAdapter) SessionName

func (l *LagerAdapter) SessionName() string

SessionName returns the name of the logger source

func (*LagerAdapter) WithData

func (l *LagerAdapter) WithData(data lager.Data) lager.Logger

WithData returns a logger with newly added data.

func (*LagerAdapter) WithTraceInfo

func (l *LagerAdapter) WithTraceInfo(req *http.Request) lager.Logger

type Logger

type Logger interface {
}

type StructWithLogValue

type StructWithLogValue struct {
	Value any
}

StructWithLogValue implements LogValue(), which allows lazy execution.

func StructValue

func StructValue(obj any) StructWithLogValue

StructValue takes an arbitrary struct. It returns a StructWithLogValue. which implements LogValue(), which return an slog.Value where struct fields are parsed as a list of slog.Attr, and returned as an grouped slog.Value.

func (StructWithLogValue) LogValue

func (r StructWithLogValue) LogValue() slog.Value

type WriteSyncer

type WriteSyncer interface {
	io.Writer
	Sync() error
}

Jump to

Keyboard shortcuts

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