Created
August 21, 2018 14:28
-
-
Save saml/dbc4d7e462fc9747a9cda5c077449764 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import logging | |
| logging.basicConfig(level='DEBUG') | |
| _log = logging.getLogger(__name__) | |
| class Ctx: | |
| def __init__(self, d): | |
| self.d = d | |
| def keys(self): | |
| return self.d.keys() | |
| def __getitem__(self, item): | |
| return self.d[item] | |
| ctx = Ctx(dict(a=1, b=2, c={'d': 3})) | |
| _log.info('Hello', extra=ctx) | |
| """ | |
| Traceback (most recent call last): | |
| File "a.py", line 13, in <module> | |
| _log.info('Hello', extra=ctx) | |
| File "/usr/lib64/python2.7/logging/__init__.py", line 1174, in info | |
| self._log(INFO, msg, args, **kwargs) | |
| File "/usr/lib64/python2.7/logging/__init__.py", line 1292, in _log | |
| record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra) | |
| File "/usr/lib64/python2.7/logging/__init__.py", line 1268, in makeRecord | |
| for key in extra: | |
| File "a.py", line 10, in __getitem__ | |
| return self.d[item] | |
| KeyError: 0 | |
| """ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment