rs / zerolog

Zero Allocation JSON Logger
MIT License
10.33k stars 564 forks source link

Is there a recommended way to do batching of log lines and write at once ? #656

Closed shettyh closed 5 months ago

shettyh commented 5 months ago

Hi,

Trying to optimise a service where it logs for each request, for pprof got to know that each write is invoking the syscall and that is one of the performance improvements that can be done.

Is there a recommended way to do batching of writes ?. Checked Diodes, looks like write is still happens for each log line, basically i want to set a config saying max buffer size as 1000 log lines and flush at once.

Thanks

rs commented 5 months ago

Single write per log line is a guaranted behavior of zerolog. If you want a batched writes, you need to use a bufio.Writer in front of your writer.