Quantcast
Channel: CodeSection,代码区,Python开发技术文章_教程 - CodeSec
Viewing all articles
Browse latest Browse all 9596

QueueLogger and Python JSON Logger

$
0
0
Solution #2: Subclass QueueHandler

The second solution is it to subclass logutils.queue.QueueHandler as follows and add pickling support for exc_info via tblib :

# Bring in support for serializing/deserializing tracebacks # needed by QueueHandler from tblib import pickling_support pickling_support.install() class QueueHandlerWithTraceback(logutils.queue.QueueHandler): """ QueueHandler with support for pickling/unpickling Tracebacks via tblib. We only override the prepare() method to *not* set `exc_info=None` """ def __init__(self, *args, **kwargs): logutils.queue.QueueHandler.__init__(self, *args, **kwargs) def prepare(self, record): self.format(record) record.msg = record.message record.args = None return record

Instead of logutils.queue.QueueHandler , we will then use QueueHandlerWithTraceback instead above ( Sample Code ).


Viewing all articles
Browse latest Browse all 9596

Trending Articles