Skip to content

Commit 46fc1df

Browse files
Addressing Andrea's feedback
1 parent a5a12a5 commit 46fc1df

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

docs/core/logger.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ Log buffering enables you to buffer logs for a specific request or invocation. E
526526
--8<-- "examples/logger/src/getting_started_with_buffering_logs.py"
527527
```
528528

529-
#### Customizing Buffer configuration
529+
#### Configuring the buffer
530530

531531
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:
532532

@@ -548,9 +548,9 @@ When configuring log buffering, you have options to fine-tune how logs are captu
548548
--8<-- "examples/logger/src/working_with_buffering_logs_disable_on_error.py"
549549
```
550550

551-
#### Flushing on uncaught exceptions
551+
#### Flushing on exceptions
552552

553-
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.
553+
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.
554554

555555
=== "working_with_buffering_logs_uncaught_exception.py"
556556

@@ -604,13 +604,13 @@ sequenceDiagram
604604
Lambda->>Logger: logger.debug("Second debug log")
605605
Logger-->>Logger: Buffer second debug log
606606
Lambda->>Logger: logger.flush_buffer()
607-
Logger->>CloudWatch: Flush buffered debug logs to CloudWatch
607+
Logger->>CloudWatch: Emit buffered logs to stdout
608608
Lambda->>Client: Return execution result
609609
```
610610
<i>Flushing buffer manually</i>
611611
</center>
612612

613-
##### Flushing on error
613+
##### Flushing when logging an error
614614

615615
<center>
616616
```mermaid
@@ -630,14 +630,16 @@ sequenceDiagram
630630
Logger-->>Logger: Buffer third debug log
631631
Lambda->>Lambda: Exception occurs
632632
Lambda->>Logger: logger.error("Error details")
633-
Logger->>CloudWatch: Send buffered debug logs
634-
Logger->>CloudWatch: Send error log
633+
Logger->>CloudWatch: Emit buffered debug logs
634+
Logger->>CloudWatch: Emit error log
635635
Lambda->>Client: Raise exception
636636
```
637637
<i>Flushing buffer when an error happens</i>
638638
</center>
639639

640-
##### Flushing when uncaught exception happens
640+
##### Flushing on exception
641+
642+
This works only when decorating your Lambda handler with the decorator `@logger.inject_lambda_context(flush_buffer_on_uncaught_error=True)`
641643

642644
<center>
643645
```mermaid
@@ -647,14 +649,14 @@ sequenceDiagram
647649
participant Logger
648650
participant CloudWatch
649651
Client->>Lambda: Invoke Lambda
650-
Lambda->>Logger: Using decorator @logger.inject_lambda_context(flush_buffer_on_uncaught_error=True)
652+
Lambda->>Logger: Using decorator
651653
Logger-->>Lambda: Logger context injected
652654
Lambda->>Logger: logger.debug("First log")
653655
Logger-->>Logger: Buffer first debug log
654656
Lambda->>Logger: logger.debug("Second log")
655657
Logger-->>Logger: Buffer second debug log
656658
Lambda->>Lambda: Uncaught Exception
657-
Lambda->>CloudWatch: Automatically send buffered debug logs
659+
Lambda->>CloudWatch: Automatically emit buffered debug logs
658660
Lambda->>Client: Raise uncaught exception
659661
```
660662
<i>Flushing buffer when an uncaught exception happens</i>
@@ -666,13 +668,13 @@ When using log buffering to control log emissions in your AWS Lambda functions,
666668

667669
1. **How can I prevent log buffering from consuming excessive memory?** Set a `max_size` in `LoggerBufferConfig` to limit the buffer's memory footprint.
668670

669-
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.
671+
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. When this happens, we emit a warning when flushing the buffer to let you know this happened.
670672

671673
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.
672674

673675
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.
674676

675-
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.
677+
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 and emit a warning.
676678

677679
6. **What happens if Lambda times out without flushing the buffer?** Buffer will be lost and no buffered logs will be flushed.
678680

examples/logger/src/working_with_buffering_logs_different_levels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from aws_lambda_powertools.logging.buffer import LoggerBufferConfig
33
from aws_lambda_powertools.utilities.typing import LambdaContext
44

5-
logger_buffer_config = LoggerBufferConfig(max_size=20480, minimum_log_level="WARNING")
5+
logger_buffer_config = LoggerBufferConfig(minimum_log_level="WARNING")
66
logger = Logger(level="INFO", logger_buffer=logger_buffer_config)
77

88

0 commit comments

Comments
 (0)