Message320708
To give you a data point, I just hit this problem. Based on the docs and common sense, I didn't expect LoggerAdapter to throw away the other extra arguments. I strongly feel that this is a bug. I cannot see how it could be desired behavior over the one proposed by mcoolive.
My use case is as follows: I'm using python with pandas to clean up a large amount of messy data and I'm using the logging framework to keep track of data consistency issues. Most of these are not critical errors, but I still need to be aware of them. I'm using 'extra' to add contextual information at different layers, like the filename when a file is read in and the column/field name when that particular column is processed. I store that data in a structured format so that I can come back to it later if needed.
I'm currently monkey patching LoggerAdapter.record to achieve the behavior mcoolive described. Specifically:
def _LoggerAdapter_process_fixed(self: logging.LoggerAdapter, msg, kwargs):
extra = self.extra.copy()
extra.update(kwargs.get('extra', dict()))
kwargs['extra'] = extra
return msg, kwargs
logging.LoggerAdapter.process = _LoggerAdapter_process_fixed |
|
| Date |
User |
Action |
Args |
| 2018-06-29 09:56:48 | srs | set | recipients:
+ srs, vinay.sajip, matrixise, mcoolive |
| 2018-06-29 09:56:47 | srs | set | messageid: <1530266207.94.0.56676864532.issue32732@psf.upfronthosting.co.za> |
| 2018-06-29 09:56:47 | srs | link | issue32732 messages |
| 2018-06-29 09:56:47 | srs | create | |
|