-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(logger): custom function for unserializable values (JSON replace…
…r) (#2739) Co-authored-by: Andrea Amorosi <[email protected]>
- Loading branch information
1 parent
08ee657
commit fbc8688
Showing
7 changed files
with
210 additions
and
39 deletions.
There are no files selected for viewing
This file contains 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 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,9 @@ | ||
{ | ||
"level": "INFO", | ||
"message": "Serialize with custom serializer", | ||
"sampling_rate": 0, | ||
"service": "serverlessAirline", | ||
"timestamp": "2024-07-07T09:52:14.212Z", | ||
"xray_trace_id": "1-668a654d-396c646b760ee7d067f32f18", | ||
"serializedValue": [1, 2, 3] | ||
} |
This file contains 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,13 @@ | ||
import { Logger } from '@aws-lambda-powertools/logger'; | ||
import type { CustomReplacerFn } from '@aws-lambda-powertools/logger/types'; | ||
|
||
const jsonReplacerFn: CustomReplacerFn = (_: string, value: unknown) => | ||
value instanceof Set ? [...value] : value; | ||
|
||
const logger = new Logger({ serviceName: 'serverlessAirline', jsonReplacerFn }); | ||
|
||
export const handler = async (): Promise<void> => { | ||
logger.info('Serialize with custom serializer', { | ||
serializedValue: new Set([1, 2, 3]), | ||
}); | ||
}; |
This file contains 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 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 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 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