klbslog

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2024 License: MIT Imports: 17 Imported by: 0

README

klbslog

generic slog handler for klb using rest & fleet

Usage:

    slog.SetDefault(slog.New(klbslog.New(nil, nil)))

Or with options and a parent:

    slog.SetDefault(slog.New(klbslog.New(&slog.HandlerOptions{AddSource: true, Level: slog.LevelDebug}, slog.NewTextHandler(os.Stderr, nil))))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(opts *slog.HandlerOptions, parent slog.Handler) slog.Handler

func WithAttributes added in v0.1.7

func WithAttributes(ctx context.Context, args ...any) context.Context

Types

type RequestLogHandler added in v0.2.0

type RequestLogHandler struct {
	Handler http.Handler
}

RequestLogHandler is a http handler that will log every requests it handles into slog. It will also update request.Context to return the request information so it will be populated in messages sent via slog.

func (*RequestLogHandler) ServeHTTP added in v0.2.0

func (r *RequestLogHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)

type SHandler

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

func (*SHandler) Enabled

func (s *SHandler) Enabled(_ context.Context, lvl slog.Level) bool

Enabled returns if SHandler is enabled (note: it always is)

func (*SHandler) Handle

func (s *SHandler) Handle(ctx context.Context, r slog.Record) error

func (*SHandler) SetHttpClient added in v0.3.0

func (s *SHandler) SetHttpClient(client *http.Client)

SetHttpClient sets the HTTP client to use to send requests

func (*SHandler) SetTarget added in v0.3.0

func (s *SHandler) SetTarget(targetUrl string)

SetTarget sets the target url for logs to be sent to

func (*SHandler) WithAttrs

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

func (*SHandler) WithGroup

func (s *SHandler) WithGroup(name string) slog.Handler

Jump to

Keyboard shortcuts

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