Skip to content

Commit fd2e5f9

Browse files
authored
Merge pull request #202 from Nr18/logger-faq
docs: add faq section
2 parents fb0142e + 9423d08 commit fd2e5f9

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

docs/content/core/logger.mdx

+26
Original file line numberDiff line numberDiff line change
@@ -406,3 +406,29 @@ def test_lambda_handler(lambda_handler, lambda_context):
406406
test_event = {'test': 'event'}
407407
lambda_handler(test_event, lambda_context) # this will now have a Context object populated
408408
```
409+
410+
## FAQ
411+
412+
**How can I enable boto3 and botocore library logging?**
413+
414+
You can enable the `botocore` and `boto3` logs by using the `set_stream_logger` method, this method will add a stream handler
415+
for the given name and level to the logging module. By default, this logs all boto3 messages to stdout.
416+
417+
```python:title=log_botocore_and_boto3.py
418+
from typing import Dict, List
419+
from aws_lambda_powertools.utilities.typing import LambdaContext
420+
from aws_lambda_powertools import Logger
421+
422+
import boto3
423+
boto3.set_stream_logger() # highlight-line
424+
boto3.set_stream_logger('botocore') # highlight-line
425+
426+
logger = Logger()
427+
client = boto3.client('s3')
428+
429+
430+
def handler(event: Dict, context: LambdaContext) -> List:
431+
response = client.list_buckets()
432+
433+
return response.get("Buckets", [])
434+
```

0 commit comments

Comments
 (0)