Skip to content

Commit bb180bd

Browse files
committed
docs: bring your own handler feat
1 parent 4b8f556 commit bb180bd

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

docs/core/logger.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ You can change the order of [standard Logger keys](#standard-structured-keys) or
676676
}
677677
```
678678

679-
### Setting timestamp to UTC
679+
#### Setting timestamp to UTC
680680

681681
By default, this Logger and standard logging library emits records using local time timestamp. You can override this behaviour via `utc` parameter:
682682

@@ -692,7 +692,7 @@ By default, this Logger and standard logging library emits records using local t
692692
logger_in_utc.info("GMT time zone")
693693
```
694694

695-
### Custom function for unserializable values
695+
#### Custom function for unserializable values
696696

697697
By default, Logger uses `str` to handle values non-serializable by JSON. You can override this behaviour via `json_default` parameter by passing a Callable:
698698

@@ -723,6 +723,25 @@ By default, Logger uses `str` to handle values non-serializable by JSON. You can
723723
}
724724
```
725725

726+
#### Bring your own handler
727+
728+
By default, Logger uses StreamHandler and logs to standard output. You can override this behaviour via `logger_handler` parameter:
729+
730+
=== "collect.py"
731+
732+
```python hl_lines="3-4 9 12"
733+
import logging
734+
from pathlib import Path
735+
736+
from aws_lambda_powertools import Logger
737+
738+
log_file = Path("/tmp/log.json")
739+
log_file_handler = logging.FileHandler(filename=log_file)
740+
logger = Logger(service="payment", logger_handler=log_file_handler)
741+
742+
logger.info("Collecting payment")
743+
```
744+
726745
## Built-in Correlation ID expressions
727746

728747
You can use any of the following built-in JMESPath expressions as part of [inject_lambda_context decorator](#setting-a-correlation-id).

0 commit comments

Comments
 (0)