3 ms·
ContextVars are seemingly more robust and work with async. We use them quite extensively for adding context to logs.
by andrewingram 4y ago
ContextVars are seemingly more robust and work with async. We use them quite extensively for adding context to logs.
- nerdwaller 4y agoI was going to say the same, I combine ContextVars with LoggerAdapters[1]. [1] https://docs.python.org/3/library/logging.html#logging.LoggerAdapter https://docs.python.org/3/library/logging.html#logging.Logge...
- MapleWalnut 4y agoTIL that ContextVars can work in place of thread locals too. Thanks for pointing that out! I had mistakenly assumed ContextVars only worked for async code.