Permalink
Browse files

Turn on warnings and exception logging by default, and made a few sma…

…ll changes/additions necessary for tests to pass.
  • Loading branch information...
1 parent 38d7944 commit 7977c2025a5c4a7d7a2bffaaa3fd85bce056c0a5 @astrofrog astrofrog committed Apr 30, 2012
Showing with 18 additions and 4 deletions.
  1. +8 −2 astropy/config/logging_helper.py
  2. +10 −2 astropy/config/tests/test_logging.py
@@ -32,10 +32,10 @@ class LoggingError(Exception):
USE_COLOR = ConfigurationItem('use_color', True,
"Whether to use color for the level names")
-LOG_WARNINGS = ConfigurationItem('log_warnings', False,
+LOG_WARNINGS = ConfigurationItem('log_warnings', True,
"Whether to log warnings.warn calls")
-LOG_EXCEPTIONS = ConfigurationItem('log_exceptions', False,
+LOG_EXCEPTIONS = ConfigurationItem('log_exceptions', True,
"Whether to log exceptions before raising them")
LOG_TO_FILE = ConfigurationItem('log_to_file', True,
@@ -103,6 +103,9 @@ def makeRecord(self, name, level, pathname, lineno, msg, args, exc_info, func=No
def _showwarning(self, *args, **kwargs):
self.warn(args[0].message)
+ def warnings_logging_enabled(self):
+ return self._showwarning_orig is not None
+
def enable_warnings_logging(self):
'''
Enable logging of warnings.warn() calls
@@ -144,6 +147,9 @@ def _excepthook(self, type, value, traceback):
self.error(value.message, extra={'origin': origin})
self._excepthook_orig(type, value, traceback)
+ def exception_logging_enabled(self):
+ return self._excepthook_orig is not None
+
def enable_exception_logging(self):
'''
Enable logging of exceptions
@@ -7,8 +7,10 @@
from .. import log, LoggingError
-# Save original values of hooks
-_excepthook = sys.excepthook
+# Save original values of hooks. These are not the system values, but the
+# already overwritten values since the logger already gets imported before
+# this file gets executed.
+_excepthook = sys.__excepthook__
_showwarning = warnings.showwarning
@@ -25,6 +27,12 @@ def setup_function(function):
# Set up the logger
log._set_defaults()
+ # Reset hooks
+ if log.warnings_logging_enabled():
+ log.disable_warnings_logging()
+ if log.exception_logging_enabled():
+ log.disable_exception_logging()
+
def teardown_module(function):

0 comments on commit 7977c20

Please sign in to comment.