diff options
author | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2010-09-22 20:34:53 +0000 |
---|---|---|
committer | Vinay Sajip <vinay_sajip@yahoo.co.uk> | 2010-09-22 20:34:53 +0000 |
commit | f8d21c407082aea4242be446abdfc4eca720e04b (patch) | |
tree | d95c22130b11374b4a917efadf630e79923fd222 /Lib/logging/handlers.py | |
parent | b2a5a1940b8734f185e68e4c00509e0b150016ca (diff) | |
download | cpython-f8d21c407082aea4242be446abdfc4eca720e04b.tar.gz |
logging: Added QueueHandler.prepare and updated documentation.
Diffstat (limited to 'Lib/logging/handlers.py')
-rw-r--r-- | Lib/logging/handlers.py | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py index ce0673d9a1..3d7a6786a9 100644 --- a/Lib/logging/handlers.py +++ b/Lib/logging/handlers.py @@ -1176,24 +1176,39 @@ class QueueHandler(logging.Handler): """ self.queue.put_nowait(record) + def prepare(self, record): + """ + Prepares a record for queuing. The object returned by this + method is enqueued. + + The base implementation formats the record to merge the message + and arguments, and removes unpickleable items from the record + in-place. + + You might want to override this method if you want to convert + the record to a dict or JSON string, or send a modified copy + of the record while leaving the original intact. + """ + # The format operation gets traceback text into record.exc_text + # (if there's exception data), and also puts the message into + # record.message. We can then use this to replace the original + # msg + args, as these might be unpickleable. We also zap the + # exc_info attribute, as it's no longer needed and, if not None, + # will typically not be pickleable. + self.format(record) + record.msg = record.message + record.args = None + record.exc_info = None + return record + def emit(self, record): """ Emit a record. - Writes the LogRecord to the queue, preparing it for pickling first. + Writes the LogRecord to the queue, preparing it first. """ try: - # The format operation gets traceback text into record.exc_text - # (if there's exception data), and also puts the message into - # record.message. We can then use this to replace the original - # msg + args, as these might be unpickleable. We also zap the - # exc_info attribute, as it's no longer needed and, if not None, - # will typically not be pickleable. - self.format(record) - record.msg = record.message - record.args = None - record.exc_info = None - self.enqueue(record) + self.enqueue(self.prepare(record)) except (KeyboardInterrupt, SystemExit): raise except: |