// HandleLog implements log.Handler. func (h *Handler) HandleLog(e *log.Entry) error { h.mu.Lock() defer h.mu.Unlock() if h.batch == nil { h.batch = &batch.Batch{ Elastic: h.Client, Index: index(), Type: "log", } } // append system info e.WithFields(log.Fields{ "host": hostname, "pid": pid, }) h.batch.Add(e) if h.batch.Size() >= h.BufferSize { go h.flush(h.batch) h.batch = nil } return nil }