Ticket #1889: 0001-Print-stack-when-encountering-an-exception-during-lo.patch

File 0001-Print-stack-when-encountering-an-exception-during-lo.patch, 1.4 KB (added by sascha_silbe, 14 years ago)

Print stack when encountering an exception during log formatting

  • src/sugar/logger.py

    From 9d62fddab2f3a8c04744d918068df7c0bed6474b Mon Sep 17 00:00:00 2001
    From: Sascha Silbe <sascha-org-sugar-git@silbe.org>
    Date: Wed, 24 Mar 2010 12:05:14 +0100
    Subject: [PATCH] Print stack when encountering an exception during log formatting
    When encountering an exception during log formatting, the default
    log handler only shows a backtrace up to the logging function,
    hiding the actual place of the error. By printing the stack in
    addition to the exception, we can pinpoint the faulty log statement.
     src/sugar/logger.py |    6 ++++++
     1 files changed, 6 insertions(+), 0 deletions(-)
    diff --git a/src/sugar/logger.py b/src/sugar/logger.py
    index 275c57d..6a6b574 100644
    a b import collections 
    2525import errno
    2626import logging
    2727import sys
     28import traceback
    2829import os
    2930import repr as repr_
    3031import decorator
    def start(log_filename=None): 
    107108                if e.errno != errno.ENOSPC:
    108109                    raise e
     111    def handleError(record):
     112        traceback.print_exc()
     113        traceback.print_stack()
    110115    logging.basicConfig(level=logging.WARNING,
    111116            format="%(created)f %(levelname)s %(name)s: %(message)s",
    112117                        stream=SafeLogWrapper(sys.stderr))
     118    root_logger.handlers[0].handleError = handleError
    114120    if 'SUGAR_LOGGER_LEVEL' in os.environ:
    115121        set_level(os.environ['SUGAR_LOGGER_LEVEL'])