From c497cc646a95f09e197ce4bb4fb4f4da6c0e3920 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 27 Jan 2021 17:04:26 +0100 Subject: [PATCH] Add docs about reset() --- doc/01-usage.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/doc/01-usage.md b/doc/01-usage.md index 78ba83dd..fa37614e 100644 --- a/doc/01-usage.md +++ b/doc/01-usage.md @@ -7,6 +7,7 @@ - [Adding extra data in the records](#adding-extra-data-in-the-records) - [Leveraging channels](#leveraging-channels) - [Customizing the log format](#customizing-the-log-format) +- [Long running processes and avoiding memory leaks](#long-running-processes-and-avoiding-memory-leaks) ## Installation @@ -226,4 +227,22 @@ $securityLogger->pushHandler($stream); You may also reuse the same formatter between multiple handlers and share those handlers between multiple loggers. +## Long running processes and avoiding memory leaks + +When logging lots of data or especially when running background workers which +are long-lived processes and do lots of logging over long periods of time, the +memory usage of buffered handlers like FingersCrossedHandler or BufferHandler +can rise quickly. + +Monolog provides the `ResettableInterface` for this use case, allowing you to +end a log cycle and get things back to their initial state. + +Calling `$logger->reset();` means flushing/cleaning all buffers, resetting internal +state, and getting it back to a state in which it can receive log records again. + +This is the conceptual equivalent of ending a web request, and can be done +between every background job you process, or whenever appropriate. It reduces memory +usage and also helps keep logs focused on the task at hand, avoiding log leaks +between different jobs. + [Handlers, Formatters and Processors](02-handlers-formatters-processors.md) →