-
I need to add lambda as a key in my structured logs, I've tried using the following syntax but it doesn't work because lambda is a reserved word in python
Is there another way I can achieve this using the powertools logger? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
I haven't tried it specifically for this library, but you might be able to get away with implementing dictionary unpacking which might look something like this : fields_to_append = {'lambda': 'whatever'}
logger.structure_logs(append=True, **fields_to_append) or, theres always using a different field name lol 🙃 |
Beta Was this translation helpful? Give feedback.
-
Hey, thanks for opening a discussion ;) Sure, try this and let us know if it works, as this is a problem for any reserved keyword for function kwarg: logger.structure_logs(append=True, **{"lambda": "whatever"}) I'd typically ask what the use case is as together we might come up with a better name, but I'd leave at your discretion. Thanks |
Beta Was this translation helpful? Give feedback.
-
Sure thing :) Both suggestions work as it's a common solution for not only
using reserved keyword as keyword arguments but also to long function
parameter calls when you use a dic - Just tested with Logger to triple
check.
from aws_lambda_powertools import Logger
logger = Logger(service="discussion_367")
# literal form
logger.structure_logs(append=True, **{"lambda": "test"})
# from a dict
keys_to_append = {"lambda": "test"}
logger.structure_logs(append=True, **keys_to_append)
logger.info("hello")
```json
{"level": "INFO", "location": "<module>:6", "message": "hello",
"timestamp": "2021-03-26 21:02:22,477", "service": "discussion_367",
"sampling_rate": 0.0, "lambda": "test"}
```
…On Fri, 26 Mar 2021 at 20:53, Padwicker ***@***.***> wrote:
Thanks for the suggestions :) I'll get back to you with results. I just
need to use that key to get our logging to work nicely with datadog.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#367 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAZPQBESME2TIUXK7EY2HJLTFTQ4ZANCNFSM4Z32DXPA>
.
|
Beta Was this translation helpful? Give feedback.
I haven't tried it specifically for this library, but you might be able to get away with implementing dictionary unpacking which might look something like this :
or, theres always using a different field name lol 🙃