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 |
25 | 25 | import errno |
26 | 26 | import logging |
27 | 27 | import sys |
| 28 | import traceback |
28 | 29 | import os |
29 | 30 | import repr as repr_ |
30 | 31 | import decorator |
… |
… |
def start(log_filename=None): |
107 | 108 | if e.errno != errno.ENOSPC: |
108 | 109 | raise e |
109 | 110 | |
| 111 | def handleError(record): |
| 112 | traceback.print_exc() |
| 113 | traceback.print_stack() |
| 114 | |
110 | 115 | logging.basicConfig(level=logging.WARNING, |
111 | 116 | format="%(created)f %(levelname)s %(name)s: %(message)s", |
112 | 117 | stream=SafeLogWrapper(sys.stderr)) |
| 118 | root_logger.handlers[0].handleError = handleError |
113 | 119 | |
114 | 120 | if 'SUGAR_LOGGER_LEVEL' in os.environ: |
115 | 121 | set_level(os.environ['SUGAR_LOGGER_LEVEL']) |