Skip to content

How to log output something like a structured dict object instead of a serialized string #2086

Closed Answered by heitorlessa
mirumirumi asked this question in Q&A
Discussion options

You must be logged in to vote

hey @mirumirumi, for Rust, I'd defer to @nmoutschen. For Python, we're not doing any special on that regard other than serializing to str any non-serializable value. Also, note that you can have additional fields at the root (in parallel to message key), when you pass additional key-value pairs after the logging message.

Here's a quick example I ran locally:

from aws_lambda_powertools import Logger
from typing import Any

logger = Logger(service="discussion-2086")

nested_dict: dict[str, Any] = {
    "products": [
        {"id": "8dbc54d1-6e5c-4f9b-8f4c-2a5fd3e2b2a7", "description": "dummy"},
    ],
    "customer_id": "95126722-4665-4a44-8150-8e12233c9bcd",
}

logger.info("Incoming products"

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by heitorlessa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants