You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/core/logger.md
+147Lines changed: 147 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -514,6 +514,153 @@ The following environment variables are available to configure Logger at a globa
514
514
515
515
## Advanced
516
516
517
+
### Buffering logs
518
+
519
+
Log buffering enables you to buffer logs for a specific request or invocation. Enable log buffering by passing `logger_buffer` when initializing a Logger instance. You can buffer logs at the `WARNING`, `INFO` or `DEBUG` level, and flush them automatically on error or manually as needed.
520
+
521
+
!!! tip "This is useful when you want to keep logs clean while still providing detailed diagnostic information when needed."
When configuring log buffering, you have options to fine-tune how logs are captured, stored, and emitted. You can configure the following parameters in the `LoggerBufferConfig` constructor:
Use the `@logger.inject_lambda_context` decorator to automatically flush buffered logs when an uncaught exception occurs in your Lambda function. The `flush_buffer_on_uncaught_error` parameter captures and flush all buffered logs records before the Lambda execution terminates.
When using log buffering to control log emissions in your AWS Lambda functions, it's important to follow best practices to avoid introducing complexity or unnecessary overhead. Keep these guidelines in mind:
651
+
652
+
1.**How can I prevent log buffering from consuming excessive memory?** Set a `max_size` in `LoggerBufferConfig` to limit the buffer's memory footprint.
653
+
654
+
2.**What happens if the log buffer reaches its maximum size?** The oldest logs are discarded when the buffer is full, making room for new logs. You need to set an appropriate `max_size` configuration.
655
+
656
+
3.**Can I customize when logs are flushed?** Yes, use the `flush_on_error=True` in `LoggerBufferConfig` or use `flush_buffer_on_uncaught_error` in `@logger.inject_lambda_context` decorator.
657
+
658
+
4.**What timestamp is used when I flush the logs?** The timestamp preserves the original time when the log record was created. If you create a log record at 11:00:10 and flush it at 11:00:25, the log line will retain its original timestamp of 11:00:10.
659
+
660
+
5.**What happens if I try to add a log line that is bigger than max buffer size?** It will not buffer, but log as a normal log.
661
+
662
+
6.**What happens if Lambda times out without flushing the buffer?** Buffer will be lost and no buffered logs will be flushed.
663
+
517
664
### Built-in Correlation ID expressions
518
665
519
666
You can use any of the following built-in JMESPath expressions as part of [inject_lambda_context decorator](#setting-a-correlation-id).
0 commit comments