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
+12-5
Original file line number
Diff line number
Diff line change
@@ -11,6 +11,7 @@ Logger provides an opinionated logger with output structured as JSON.
11
11
* Log Lambda event when instructed (disabled by default)
12
12
* Log sampling enables DEBUG log level for a percentage of requests (disabled by default)
13
13
* Append additional keys to structured log at any point in time
14
+
* Buffering logs for a specific request or invocation, and flushing them automatically on error or manually as needed.
14
15
15
16
## Getting started
16
17
@@ -530,11 +531,13 @@ Log buffering enables you to buffer logs for a specific request or invocation. E
530
531
531
532
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:
|`max_bytes`| Maximum size of the log buffer in bytes |`int` (default: 20480 bytes) |
537
+
|`buffer_at_verbosity`| Minimum log level to buffer |`DEBUG`, `INFO`, `WARNING`|
538
+
|`flush_on_error_log`| Automatically flush buffer when an error occurs |`True` (default), `False`|
539
+
540
+
!!! note "When `flush_on_error_log` is enabled, it automatically flushes for `logger.exception()`, `logger.error()`, and `logger.critical()` statements."
1. Disabling `flush_on_error_log` will not flush the buffer when logging an error. This is useful when you want to control when the buffer is flushed by calling the `logger.flush_buffer()` method.
557
+
553
558
#### Flushing on exceptions
554
559
555
560
Use the `@logger.inject_lambda_context` decorator to automatically flush buffered logs when an exception is raised in your Lambda function. The `flush_buffer_on_uncaught_error` parameter captures and flush all buffered logs records before the Lambda execution terminates.
@@ -567,6 +572,8 @@ If you are using log buffering, we recommend sharing the same log instance acros
567
572
!!! note "Buffer Inheritance"
568
573
Loggers created with the same `service_name` automatically inherit the buffer configuration from the first initialized logger with a buffer configuration.
569
574
575
+
Child loggers instances inherit their parent's buffer configuration but maintain a separate buffer.
0 commit comments