MCPcopy
hub / github.com/pocketbase/pocketbase / WriteAll

Method WriteAll

tools/logger/batch_handler.go:202–227  ·  view source on GitHub ↗

WriteAll writes all accumulated Log entries and resets the batch queue.

(ctx context.Context)

Source from the content-addressed store, hash-verified

200
201// WriteAll writes all accumulated Log entries and resets the batch queue.
202func (h *BatchHandler) WriteAll(ctx context.Context) error {
203 if h.parent != nil {
204 // invoke recursively the parent level handler since the most
205 // top level one is holding the logs queue.
206 return h.parent.WriteAll(ctx)
207 }
208
209 h.mux.Lock()
210
211 totalLogs := len(h.logs)
212
213 // no logs to write
214 if totalLogs == 0 {
215 h.mux.Unlock()
216 return nil
217 }
218
219 // create a copy of the logs slice to prevent blocking during write
220 logs := make([]*Log, totalLogs)
221 copy(logs, h.logs)
222 h.logs = h.logs[:0] // reset
223
224 h.mux.Unlock()
225
226 return h.options.WriteFunc(ctx, logs)
227}
228
229// resolveAttr writes attr into data.
230func (h *BatchHandler) resolveAttr(data map[string]any, attr slog.Attr) error {

Callers 4

TestBatchHandlerWriteAllFunction · 0.95
HandleMethod · 0.95
initLoggerMethod · 0.95

Calls 1

copyFunction · 0.85

Tested by 2

TestBatchHandlerWriteAllFunction · 0.76