log

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: Apache-2.0 Imports: 15 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	DefaultLogLevel       = slog.LevelInfo
	DefaultDebugLogFormat = PrettyLog
	DefaultLogFormat      = JSONLog
)

Defaults

View Source
const BodyDiffKey = "body.diff"
View Source
const BodyDumpKey = "body.dump"

Variables

View Source
var DefaultLogOutput = os.Stdout

Functions

func BodyDiff

func BodyDiff(diff string) slog.Attr

func BodyDump

func BodyDump(dump string) slog.Attr

func Bytes

func Bytes(obj interface{}) []byte

func DebugBodyChanges

func DebugBodyChanges(logger *slog.Logger, msg string, resourceType string, inBytes, rwrBytes []byte)

DebugBodyChanges logs debug message with diff between 2 bodies.

func DebugBodyHead

func DebugBodyHead(logger *slog.Logger, msg, resourceType string, obj []byte)

DebugBodyHead logs head of input slice.

func Diff

func Diff(json1, json2 []byte) (string, error)

Diff returns a human-readable diff between 2 JSONs suitable for debugging. See: https://github.com/josephburnett/jd/blob/master/README.md

func HasData

func HasData(obj interface{}) bool

func HeadString

func HeadString(obj interface{}, limit int) string

func HeadStringEx

func HeadStringEx(obj interface{}, limit int) string

func SetupDefaultLoggerFromEnv

func SetupDefaultLoggerFromEnv(opts Options)

func SetupHandler

func SetupHandler(opts Options) slog.Handler

func SlogErr

func SlogErr(err error) slog.Attr

Types

type Format

type Format string
const (
	JSONLog   Format = "json"
	TextLog   Format = "text"
	PrettyLog Format = "pretty"
)

type Options

type Options struct {
	Level  string
	Format string
	Output string
}

type Output

type Output string
const (
	Stdout  Output = "stdout"
	Stderr  Output = "stderr"
	Discard Output = "discard"
)

type PrettyHandler

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

PrettyHandler is a pretty print handler close to default slog handler.

func NewPrettyHandler

func NewPrettyHandler(w io.Writer, opts *slog.HandlerOptions) *PrettyHandler

func (*PrettyHandler) Enabled

func (h *PrettyHandler) Enabled(ctx context.Context, l slog.Level) bool

Enabled returns if level is enabled for this handler.

func (*PrettyHandler) Handle

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

func (*PrettyHandler) WithAttrs

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

func (*PrettyHandler) WithGroup

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

WithGroup adds group

type ReaderLogger

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

ReaderLogger is ReadCloser implementation that catches content while underlying Reader is being read, e.g. with io.Copy. Content is copied into the buffer and may be used after copying for logging or other handling.

func NewReaderLogger

func NewReaderLogger(r io.Reader) *ReaderLogger

func (*ReaderLogger) Close

func (r *ReaderLogger) Close() error

func (*ReaderLogger) Read

func (r *ReaderLogger) Read(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

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