Index: Lib/distutils/log.py =================================================================== --- Lib/distutils/log.py (révision 72457) +++ Lib/distutils/log.py (copie de travail) @@ -1,22 +1,29 @@ """A simple log mechanism styled after PEP 282.""" +import sys +import logging +try: + import logging + LOGGING_PRESENT = True + from warnings import warn +except ImportError: + LOGGING_PRESENT = False -# The class here is styled after PEP 282 so that it could later be -# replaced with a standard Python logging implementation. - DEBUG = 1 INFO = 2 WARN = 3 ERROR = 4 FATAL = 5 -import sys - class Log: - def __init__(self, threshold=WARN): self.threshold = threshold def _log(self, level, msg, args): + if LOGGING_PRESENT: + warn(("Distutils.log.Log is deprecated, use the regular logging " + "module with \"logging.getLogger('distutils')\""), + PendingDeprecationWarning) + if level >= self.threshold: if args: msg = msg % args @@ -39,30 +46,65 @@ def warn(self, msg, *args): self._log(WARN, msg, args) + def warning(self, msg, *args): + self._log(WARN, msg, args) + def error(self, msg, *args): self._log(ERROR, msg, args) def fatal(self, msg, *args): self._log(FATAL, msg, args) -_global_log = Log() -log = _global_log.log -debug = _global_log.debug -info = _global_log.info -warn = _global_log.warn -error = _global_log.error -fatal = _global_log.fatal - -def set_threshold(level): - # return the old threshold for use from tests - old = _global_log.threshold - _global_log.threshold = level - return old - def set_verbosity(v): + if LOGGING_PRESENT: + warn(("Distutils.log.set_verbosity is deprecated, use the regular " + "logging module with \"logging.getLogger('distutils')\""), + PendingDeprecationWarning) if v <= 0: set_threshold(WARN) elif v == 1: set_threshold(INFO) elif v >= 2: set_threshold(DEBUG) + +if LOGGING_PRESENT: + import logging + logger = logging.getLogger('distutils') + + levels = {DEBUG: logging.DEBUG, + INFO: logging.INFO, + WARN: logging.WARNING, + ERROR: logging.ERROR, + FATAL: logging.CRITICAL} + + def set_threshold(level): + import pdb; pdb.set_trace() + warn(("Distutils.log.threshold is deprecated, use the regular " + "logging module with \"logging.getLogger('distutils')\""), + PendingDeprecationWarning) + + old_level = logger.level + logger.setLevel(levels[level]) + for deprecated_level, level in levels.items(): + if old_level == level: + return deprecated_level + return DEBUG +else: + # minimum logging system, kept for Python build + # to avoid importing the logging module + logger = Log() + + def set_threshold(level): + # return the old threshold for use from tests + old = logger.threshold + logger.threshold = level + return old + +log = logger.log +debug = logger.debug +info = logger.info +warn = logger.warn +warning = logger.warn +error = logger.error +fatal = logger.fatal +