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
+20Lines changed: 20 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -760,6 +760,26 @@ This is how the printed log would look:
760
760
!!! tip "Custom Log formatter and Child loggers"
761
761
It is not necessary to pass the `LogFormatter` each time a [child logger](#using-multiple-logger-instances-across-your-code) is created. The parent's LogFormatter will be inherited by the child logger.
762
762
763
+
### Bring your own JSON serializer
764
+
765
+
You can extend the default JSON serializer by passing a custom serializer function to the `Logger` constructor, using the `jsonReplacerFn` option. This is useful when you want to customize the serialization of specific values.
By default, Logger uses `JSON.stringify()` to serialize log items and a [custom replacer function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#the_replacer_parameter) to serialize common unserializable values such as `BigInt`, circular references, and `Error` objects.
780
+
781
+
When you extend the default JSON serializer, we will call your custom serializer function before the default one. This allows you to customize the serialization while still benefiting from the default behavior.
* A custom JSON replacer function that is used to serialize the log items.
685
+
*
686
+
* By default, we already extend the default serialization behavior to handle `BigInt` and `Error` objects, as well as remove circular references.
687
+
* When a custom JSON replacer function is passed to the Logger constructor, it will be called **before** our custom rules for each key-value pair in the object being stringified.
688
+
*
689
+
* This allows you to customize the serialization while still benefiting from the default behavior.
690
+
*
691
+
* @see {@link ConstructorOptions.jsonReplacerFn}
692
+
*
693
+
* @param key - The key of the value being stringified.
Copy file name to clipboardExpand all lines: packages/logger/src/types/Logger.ts
+23Lines changed: 23 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -28,13 +28,35 @@ type InjectLambdaContextOptions = {
28
28
resetKeys?: boolean;
29
29
};
30
30
31
+
/**
32
+
* A custom JSON replacer function that can be passed to the Logger constructor to extend the default serialization behavior.
33
+
*
34
+
* By default, we already extend the default serialization behavior to handle `BigInt` and `Error` objects, as well as remove circular references.
35
+
* When a custom JSON replacer function is passed to the Logger constructor, it will be called **before** our custom rules for each key-value pair in the object being stringified.
36
+
*
37
+
* This allows you to customize the serialization while still benefiting from the default behavior.
38
+
*
39
+
* @param key - The key of the value being stringified.
* A custom JSON replacer function that can be passed to the Logger constructor to extend the default serialization behavior.
53
+
*
54
+
* By default, we already extend the default serialization behavior to handle `BigInt` and `Error` objects, as well as remove circular references.
55
+
* When a custom JSON replacer function is passed to the Logger constructor, it will be called **before** our custom rules for each key-value pair in the object being stringified.
56
+
*
57
+
* This allows you to customize the serialization while still benefiting from the default behavior.
0 commit comments