log

package
v0.0.0-...-c41706e Latest Latest
Warning

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

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

Documentation

Overview

Package log provides a structured logging base on slog.

Sampling

It supports sampling Info logs to reduce the log volume using sampler provided by WithSampler. However, if there exists an Error log, it records buffered Info logs for same request event they are not sampled. It provides context for root cause analysis while Error happens.

Trace Integration

It supports recording log records as trace span's events if it's enabled by WithLogAsTraceEvent. It could significantly reduce the log volume then cost as trace is priced by number of span.

Rate limiting

Applications often experience runs of errors, either because of a bug or because of a misbehaving user. Logging errors is usually a good idea, but it can easily make this bad situation worse: not only is your application coping with a flood of errors, it's also spending extra CPU cycles and I/O logging those errors. Since writes are typically serialized, logging limits throughput when you need it most.

Rate limiting fixes this problem by dropping repetitive log entries. Under normal conditions, your application writes out every entry. When similar entries are logged hundreds or thousands of times each second, though, it begins dropping duplicates to preserve throughput.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(opts ...Option) *slog.Logger

New creates a new slog.Logger with the given Option(s).

Types

type Option

type Option func(*options)

Option configures the logger with specific options.

func WithHandler

func WithHandler(handler slog.Handler) Option

WithHandler provides a customized slog.Handler.

By default, it uses the default handler in slog.

func WithSampler

func WithSampler(sampler func(context.Context) bool) Option

WithSampler provides a sampler function which decides whether Info logs should write to output.

By default, it disables simpling with nil sampler.

Jump to

Keyboard shortcuts

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