Skip to content

Hook on logging events to add dynamic keys? #5455

Closed Answered by leandrodamascena
JP-Ellis asked this question in Q&A
Discussion options

You must be logged in to vote

Ok, I get the use case now, in theory you don't need append_keys, but you need to add keys that you can mutate during the execution of your function, but without adding too much new code. I think in this case you might have the benefit of using a CustomFormatter and then overriding the serialize method to add those keys dynamically. Please check if this code make sense for you

from aws_lambda_powertools import Logger
from aws_lambda_powertools.logging.formatter import LambdaPowertoolsFormatter
from aws_lambda_powertools.logging.types import LogRecord
from contextvars import ContextVar


my_context_var = ContextVar("my_default_key", default="my_default")

class CustomFormatter(LambdaPowert…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@JP-Ellis
Comment options

@leandrodamascena
Comment options

Answer selected by JP-Ellis
@JP-Ellis
Comment options

@leandrodamascena
Comment options

@JP-Ellis
Comment options

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