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
By default, Logger uses [LambdaPowertoolsFormatter](#lambdapowertoolsformatter) that persists its custom structure between non-cold start invocations. There could be scenarios where the existing feature set isn't sufficient to your formatting needs.
864
864
865
-
For **minor changes like remapping keys** after all log record processing has completed, you can override `serialize` method from [LambdaPowertoolsFormatter](#lambdapowertoolsformatter):
865
+
???+ info
866
+
The most common use cases are remapping keys by bringing your existing schema, and redacting sensitive information you know upfront.
867
+
868
+
For these, you can override the `serialize` method from [LambdaPowertoolsFormatter](#lambdapowertoolsformatter).
866
869
867
870
=== "custom_formatter.py"
868
871
@@ -892,28 +895,39 @@ For **minor changes like remapping keys** after all log record processing has co
892
895
}
893
896
```
894
897
895
-
For **replacing the formatter entirely**, you can subclass `BasePowertoolsFormatter`, implement `append_keys` method, and override `format` standard logging method. This ensures the current feature set of Logger like [injecting Lambda context](#capturing-lambda-context-info) and [sampling](#sampling-debug-logs) will continue to work.
898
+
The `log` argument is the final log record containing [our standard keys](#standard-structured-keys), optionally [Lambda context keys](#capturing-lambda-context-info), and any custom key you might have added via [append_keys](#append_keys-method) or the [extra parameter](#extra-parameter).
899
+
900
+
For exceptional cases where you want to completely replace our formatter logic, you can subclass `BasePowertoolsFormatter`.
901
+
902
+
???+ warning
903
+
You will need to implement `append_keys`, `clear_state`, override `format`, and optionally `remove_keys` to keep the same feature set Powertools Logger provides. This also means keeping state of logging keys added.
896
904
897
-
???+ info
898
-
You might need to implement `remove_keys` method if you make use of the feature too.
899
905
900
906
=== "collect.py"
901
907
902
-
```python hl_lines="2 4 7 12 16 27"
908
+
```python hl_lines="5 7 9-10 13 17 21 24 35"
909
+
import logging
910
+
from typing import Iterable, List, Optional
911
+
903
912
from aws_lambda_powertools import Logger
904
913
from aws_lambda_powertools.logging.formatter import BasePowertoolsFormatter
905
914
906
915
class CustomFormatter(BasePowertoolsFormatter):
907
-
custom_format = {} # arbitrary dict to hold our structured keys
0 commit comments