-
Notifications
You must be signed in to change notification settings - Fork 156
feat(logger): time zone aware timestamp in Logger #2710
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
dreamorosi
merged 21 commits into
aws-powertools:main
from
arnabrahman:1774-logger-timezone-aware-timestamp
Jul 3, 2024
Merged
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
bdc225a
feat: format timestamp with timezone offset
arnabrahman d6f6a28
test: formatTimestamp with different timezone
arnabrahman c8d1899
Merge branch 'main' into 1774-logger-timezone-aware-timestamp
arnabrahman 2238370
feat: get timezone from `envVarsService` during formatting
arnabrahman ae74643
fix: formatTimestamp tests when `envVarsService` is present
arnabrahman 35da8d5
feat: formatTimestamp tests when `envVarsService` is not present
arnabrahman c1d0c61
fix: update comparison as default `TZ` value is `:UTC`
arnabrahman fc0cb73
docs: custom timezone section with examples
arnabrahman 0903e5a
doc: fix the special note
arnabrahman 020e5d8
test: group the test cases close the each other
arnabrahman 8eeb735
Merge branch 'main' into 1774-logger-timezone-aware-timestamp
dreamorosi 8d03e87
Update docs/core/logger.md
dreamorosi 8b29c00
Update docs/core/logger.md
arnabrahman b92db99
Update docs/core/logger.md
arnabrahman b58d58c
Update docs/core/logger.md
arnabrahman 51bf3d7
Update docs/core/logger.md
arnabrahman 4e633ac
Update examples/snippets/logger/customTimezone.ts
arnabrahman ed60848
Update examples/snippets/logger/customTimezoneOutput.json
arnabrahman 1fb398e
Update docs/core/logger.md
arnabrahman 2997dd1
Merge branch 'main' into 1774-logger-timezone-aware-timestamp
dreamorosi 47c813f
Merge branch 'main' into 1774-logger-timezone-aware-timestamp
dreamorosi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Logger } from '@aws-lambda-powertools/logger'; | ||
|
||
export const handler = async (_event, _context): Promise<void> => { | ||
const loggerInUTC = new Logger({ serviceName: 'payment' }); | ||
loggerInUTC.info('Logging with default AWS Lambda timezone: UTC time'); | ||
|
||
process.env.TZ = 'US/Eastern'; // (1)! | ||
|
||
const logger = new Logger({ serviceName: 'order' }); | ||
logger.info('Logging with US Eastern timezone'); | ||
}; | ||
arnabrahman marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
[ | ||
{ | ||
"level": "INFO", | ||
"message": "Logging with default AWS Lambda timezone: UTC time", | ||
"sampling_rate": 0, | ||
"service": "payment", | ||
"timestamp": "2024-06-23T12:29:34.721Z", | ||
"xray_trace_id": "1-6678152e-4f2ffb716d51f4112ec21b1d" | ||
}, | ||
{ | ||
"level": "INFO", | ||
"message": "Logging with US Eastern timezone", | ||
"sampling_rate": 0, | ||
"service": "order", | ||
"timestamp": "2024-06-23T08:29:34.814-04:00", | ||
"xray_trace_id": "1-6678152e-4f2ffb716d51f4112ec21b1d" | ||
} | ||
arnabrahman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.