package
0.0.0-20241202154501-5d0588ee4786
Repository: https://github.com/geerew/off-course.git
Documentation: pkg.go.dev
# Functions
BasicWriteFn is a WriteFn that writes logs to stdout.
InitLogger initializes a logger with a batch handler
During testing, the batchSize should be set to 1 to ensure that logs are written immediately.
NewBatchHandler creates a slog compatible handler that writes JSON logs on batches
Panics if [BatchOptions.WriteFn] is not defined
Example:
l := slog.New(logger.NewBatchHandler(logger.BatchOptions{ WriteFn: func(ctx context.Context, logs []*Log) error { for _, l := range logs { fmt.Println(l.Level, l.Message, l.Data) } return nil } })) l.Info("Example message", "title", "lorem ipsum").
NilWriteFn is a WriteFn that does nothing.
TestWriteFn is a WriteFn that writes logs to a slice.
# Structs
BatchHandler is a slog handler that writes records on batches.
BatchOptions are options for the BatchHandler.
No description provided by the author
# Type aliases
BeforeAddFn is a function that is invoked every time before a new log is added to the batch queue.
WriteFn is a function that processes a batch of logs.