MCPcopy
hub / github.com/pocketbase/pocketbase / NewBatchHandler

Function NewBatchHandler

tools/logger/batch_handler.go:53–74  ·  view source on GitHub ↗

NewBatchHandler creates a slog compatible handler that writes JSON logs on batches (default to 100), using the given options. Panics if [BatchOptions.WriteFunc] is not defined. Example: l := slog.New(logger.NewBatchHandler(logger.BatchOptions{ WriteFunc: func(ctx context.Context, logs []*Lo

(options BatchOptions)

Source from the content-addressed store, hash-verified

51// }))
52// l.Info("Example message", "title", "lorem ipsum")
53func NewBatchHandler(options BatchOptions) *BatchHandler {
54 h := &BatchHandler{
55 mux: &sync.Mutex{},
56 options: &options,
57 }
58
59 if h.options.WriteFunc == nil {
60 panic("options.WriteFunc must be set")
61 }
62
63 if h.options.Level == nil {
64 h.options.Level = slog.LevelInfo
65 }
66
67 if h.options.BatchSize == 0 {
68 h.options.BatchSize = 100
69 }
70
71 h.logs = make([]*Log, 0, h.options.BatchSize)
72
73 return h
74}
75
76// BatchHandler is a slog handler that writes records on batches.
77//

Callers 9

initLoggerMethod · 0.92
TestNewBatchHandlerPanicFunction · 0.85
TestBatchHandlerEnabledFunction · 0.85
TestBatchHandlerSetLevelFunction · 0.85
TestBatchHandlerHandleFunction · 0.85
TestBatchHandlerWriteAllFunction · 0.85

Calls

no outgoing calls

Tested by 8

TestNewBatchHandlerPanicFunction · 0.68
TestBatchHandlerEnabledFunction · 0.68
TestBatchHandlerSetLevelFunction · 0.68
TestBatchHandlerHandleFunction · 0.68
TestBatchHandlerWriteAllFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…