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
+19-9
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,7 @@ Your Logger will include the following keys to your structured logging:
39
39
|**level**: `str`|`INFO`| Logging level |
40
40
|**location**: `str`|`collect.handler:1`| Source code location where statement was executed |
41
41
|**message**: `Any`|`Collecting payment`| Unserializable JSON values are casted as `str`|
42
-
|**timestamp**: `str`|`2021-05-03 10:20:19,650+0200`| Timestamp with milliseconds, by default uses local timezone |
42
+
|**timestamp**: `str`|`2021-05-03 10:20:19,650+0000`| Timestamp with milliseconds, by default uses default AWS Lambda timezone (UTC)|
43
43
|**service**: `str`|`payment`| Service name defined, by default `service_undefined`|
44
44
|**xray_trace_id**: `str`|`1-5759e988-bd862e3fe1be46a994272793`| When [tracing is enabled](https://docs.aws.amazon.com/lambda/latest/dg/services-xray.html){target="_blank"}, it shows X-Ray Trace ID |
45
45
|**sampling_rate**: `float`|`0.1`| When enabled, it shows sampling rate in percentage e.g. 10% |
@@ -337,12 +337,12 @@ By default, the Logger will automatically include the full stack trace in JSON f
337
337
338
338
### Date formatting
339
339
340
-
Logger uses Python's standard logging date format with the addition of timezone: `2021-05-03 11:47:12,494+0200`.
340
+
Logger uses Python's standard logging date format with the addition of timezone: `2021-05-03 11:47:12,494+0000`.
341
341
342
342
You can easily change the date format using one of the following parameters:
343
343
344
344
***`datefmt`**. You can pass any [strftime format codes](https://strftime.org/){target="_blank" rel="nofollow"}. Use `%F` if you need milliseconds.
345
-
***`use_rfc3339`**. This flag will use a format compliant with both RFC3339 and ISO8601: `2022-10-27T16:27:43.738+02:00`
345
+
***`use_rfc3339`**. This flag will use a format compliant with both RFC3339 and ISO8601: `2022-10-27T16:27:43.738+00:00`
346
346
347
347
???+ tip "Prefer using [datetime string formats](https://docs.python.org/3/library/datetime.html#strftime-and-strptime-format-codes){target="_blank" rel="nofollow"}?"
348
348
Use `use_datetime_directive` flag along with `datefmt` to instruct Logger to use `datetime` instead of `time.strftime`.
@@ -368,6 +368,7 @@ The following environment variables are available to configure Logger at a globa
368
368
|**Event Logging**| Whether to log the incoming event. |`POWERTOOLS_LOGGER_LOG_EVENT`|`false`|
369
369
|**Debug Sample Rate**| Sets the debug log sampling. |`POWERTOOLS_LOGGER_SAMPLE_RATE`|`0`|
370
370
|**Disable Deduplication**| Disables log deduplication filter protection to use Pytest Live Log feature. |`POWERTOOLS_LOG_DEDUPLICATION_DISABLED`|`false`|
371
+
|**TZ**| Sets timezone when using Logger, e.g., `US/Eastern`. Timezone is defaulted to UTC when `TZ` is not set |`TZ`|`None` (UTC) |
371
372
372
373
[`POWERTOOLS_LOGGER_LOG_EVENT`](#logging-incoming-event) can also be set on a per-method basis, and [`POWERTOOLS_LOGGER_SAMPLE_RATE`](#sampling-debug-logs) on a per-instance basis. These parameter values will override the environment variable value.
373
374
@@ -464,7 +465,7 @@ If you prefer configuring it separately, or you'd want to bring this JSON Format
464
465
|**`json_default`**| function to coerce unserializable values, when no custom serializer/deserializer is set |`str`|
465
466
|**`datefmt`**| string directives (strftime) to format log timestamp |`%Y-%m-%d %H:%M:%S,%F%z`, where `%F` is a custom ms directive |
466
467
|**`use_datetime_directive`**| format the `datefmt` timestamps using `datetime`, not `time` (also supports the custom `%F` directive for milliseconds) |`False`|
467
-
|**`utc`**|set logging timestamp to UTC |`False`|
468
+
|**`utc`**|enforce logging timestamp to UTC (ignore `TZ` environment variable)|`False`|
468
469
|**`log_record_order`**| set order of log keys when logging |`["level", "location", "message", "timestamp"]`|
469
470
|**`kwargs`**| key-value to be included in log messages |`None`|
470
471
@@ -583,17 +584,26 @@ You can change the order of [standard Logger keys](#standard-structured-keys) or
By default, this Logger and standard logging library emits records using local time timestamp. You can override this behavior via `utc` parameter:
589
+
By default, this Logger and the standard logging library emit records with the default AWS Lambda timestamp in **UTC**.
589
590
590
-
=== "setting_utc_timestamp.py"
591
+
<!-- markdownlint-disable MD013 -->
592
+
If you prefer to log in a specific timezone, you can configure it by setting the `TZ` environment variable. You can do this either as an AWS Lambda environment variable or directly within your Lambda function settings. [Click here](https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime){target="_blank"} for a comprehensive list of available Lambda environment variables.
593
+
<!-- markdownlint-enable MD013 -->
594
+
595
+
???+ tip
596
+
`TZ` environment variable will be ignored if `utc` is set to `True`
Copy file name to clipboardExpand all lines: examples/logger/src/logging_uncaught_exceptions_output.json
+1-1
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
"level": "ERROR",
3
3
"location": "log_uncaught_exception_hook:756",
4
4
"message": "500 Server Error: INTERNAL SERVER ERROR for url: http://httpbin.org/status/500",
5
-
"timestamp": "2022-11-16 13:51:29,198+0100",
5
+
"timestamp": "2022-11-16 13:51:29,198+0000",
6
6
"service": "payment",
7
7
"exception": "Traceback (most recent call last):\n File \"<input>\", line 52, in <module>\n handler({}, {})\n File \"<input>\", line 17, in handler\n ret.raise_for_status()\n File \"<input>/lib/python3.9/site-packages/requests/models.py\", line 1021, in raise_for_status\n raise HTTPError(http_error_msg, response=self)\nrequests.exceptions.HTTPError: 500 Server Error: INTERNAL SERVER ERROR for url: http://httpbin.org/status/500",
0 commit comments