Skip to content

Commit 5ac2ca3

Browse files
committed
docs(logger): add example on how to set UTC timestamp (#392)
Signed-off-by: heitorlessa <[email protected]>
1 parent 72a8e57 commit 5ac2ca3

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/core/logger.md

+22
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ Service is what defines the Logger name, including what the Lambda function is r
531531
For Logger, the `service` is the logging key customers can use to search log operations for one or more functions - For example, **search for all errors, or messages like X, where service is payment**.
532532

533533
??? tip "Logging output example"
534+
534535
```json hl_lines="5"
535536
{
536537
"timestamp": "2020-05-24 18:17:33,774",
@@ -571,6 +572,7 @@ A common issue when migrating from other Loggers is that `service` might be defi
571572

572573
logger = Logger(child=True)
573574
```
575+
574576
=== "correct_logger_inheritance.py"
575577

576578
```python hl_lines="4 10"
@@ -652,6 +654,26 @@ You can also change the order of the following log record keys via the `log_reco
652654
}
653655
```
654656

657+
#### Setting timestamp to UTC
658+
659+
By default, this Logger and standard logging library emits records using local time timestamp. You can override this behaviour by updating the current converter set in our formatter:
660+
661+
=== "app.py"
662+
663+
```python hl_lines="1 3 9"
664+
from aws_lambda_powertools import Logger
665+
666+
import time
667+
668+
logger = Logger(service="sample_service")
669+
670+
logger.info("Local time")
671+
672+
logger._logger.handlers[0].formatter.converter = time.gmtime
673+
674+
logger.info("GMT time")
675+
```
676+
655677
## Testing your code
656678

657679
When unit testing your code that makes use of `inject_lambda_context` decorator, you need to pass a dummy Lambda Context, or else Logger will fail.

0 commit comments

Comments
 (0)