Skip to content

docs(logger): add example on how to set UTC timestamp #392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/core/logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ Service is what defines the Logger name, including what the Lambda function is r
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**.

??? tip "Logging output example"

```json hl_lines="5"
{
"timestamp": "2020-05-24 18:17:33,774",
Expand Down Expand Up @@ -571,6 +572,7 @@ A common issue when migrating from other Loggers is that `service` might be defi

logger = Logger(child=True)
```

=== "correct_logger_inheritance.py"

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

#### Setting timestamp to UTC

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:

=== "app.py"

```python hl_lines="1 3 9"
from aws_lambda_powertools import Logger

import time

logger = Logger(service="sample_service")

logger.info("Local time")

logger._logger.handlers[0].formatter.converter = time.gmtime

logger.info("GMT time")
```

## Testing your code

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.
Expand Down