Documentation ¶
Overview ¶
Package log implements a simple logging handler.
Index ¶
Examples ¶
Constants ¶
View Source
const ( // ImmediateLevel is the severity which if a log event has, it is logged immediately without buffering. LevelImmediate = slog.Level(-6142973) )
Variables ¶
This section is empty.
Functions ¶
func New ¶
New returns a function that returns an slog.Logger The logger is backed by a handler that stores log messages into a circular buffer. Those log messages are only flushed to the underlying io.Writer when a message with level >= slog.LevelError is logged. A unique logID is also added to the logs that acts as a correlation id of log events from diffrent components that neverthless are related.
Example ¶
package main import ( "context" "errors" "os" "github.com/komuw/ong/log" ) func main() { l := log.New(os.Stdout, 1000) hey := func(ctx context.Context) { logger := l(ctx) logger.Info("sending email", "email", "jane@example.com") logger.Error("fail", errors.New("sending email failed."), "email", "jane@example.com") } hey(context.Background()) // example output: // {"time":"2023-02-03T11:26:47.460792396Z","level":"INFO","source":"main.go:17","msg":"sending email","email":"jane@example.com","logID":"DQTXGs3HM8Xgx3yt"} // {"time":"2023-02-03T11:26:47.46080217Z","level":"ERROR","source":"main.go:18","msg":"fail","err":"sending email failed.","email":"jane@example.com","logID":"DQTXGs3HM8Xgx3yt"} }
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.