log

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

func Debug(ctx context.Context, msg string, keysAndValues ...interface{})

Debug logs a debug message with optional key-value pairs.

func Error

func Error(ctx context.Context, err error, msg string, keysAndValues ...interface{})

Error logs an error message with optional key-value pairs.

func Info

func Info(ctx context.Context, msg string, keysAndValues ...interface{})

Info logs an informational message with optional key-value pairs.

func Setup

Setup initializes the logger and returns a new context with the logger attached. The logger is configured based on the provided Parameters. The encoder and writer are selected based on the Development flag. The LogLevel parameter determines the log level of the logger. The StacktraceLevel parameter determines the log level at which a stack trace is added to log entries. The function does not modify the original context.

Example usage:

ctx := Setup(context.Background(), Parameters{
  LogLevel:        "debug",
  StacktraceLevel: "error",
  Development:     true,
})

func Warn

func Warn(ctx context.Context, msg string, keysAndValues ...interface{})

Warn logs a warning message with optional key-value pairs.

func WithValues

func WithValues(ctx context.Context, keysAndValues ...interface{}) context.Context

WithValues adds additional key-value pairs to the context's logger.

Types

type Handler

type Handler struct {
	slog.Handler
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(opts ...Option) *Handler

func (*Handler) Enabled

func (h *Handler) Enabled(ctx context.Context, level slog.Level) bool

func (*Handler) Handle

func (h *Handler) Handle(ctx context.Context, r slog.Record) error

func (*Handler) WithAttrs

func (h *Handler) WithAttrs(attrs []slog.Attr) slog.Handler

func (*Handler) WithGroup

func (h *Handler) WithGroup(name string) slog.Handler

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithLevel

func WithLevel(l slog.Leveler) Option

func WithStacktrace

func WithStacktrace(enabled bool, level slog.Leveler) Option

func WithWriter

func WithWriter(w io.Writer) Option

type Parameters

type Parameters struct {
	LogLevel         string
	StacktraceLevel  string
	EnableStacktrace bool
	Development      bool
}

Jump to

Keyboard shortcuts

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