From 9a0fc97bf4a336d81160b19a52ab4f5d2e2317e0 Mon Sep 17 00:00:00 2001 From: Jesse Noller Date: Sun, 18 Jan 2009 21:12:58 +0000 Subject: merge cl r68737 to py3k --- Lib/logging/__init__.py | 10 ++++++++++ Lib/multiprocessing/util.py | 24 ------------------------ Misc/NEWS | 3 +++ 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py index cce6ea0..ee43554 100644 --- a/Lib/logging/__init__.py +++ b/Lib/logging/__init__.py @@ -99,6 +99,11 @@ raiseExceptions = 1 logThreads = 1 # +# If you don't want multiprocessing information in the log, set this to zero +# +logMultiprocessing = 1 + +# # If you don't want process information in the log, set this to zero # logProcesses = 1 @@ -263,6 +268,11 @@ class LogRecord: else: self.thread = None self.threadName = None + if logMultiprocessing: + from multiprocessing import current_process + self.processName = current_process().name + else: + self.processName = None if logProcesses and hasattr(os, 'getpid'): self.process = os.getpid() else: diff --git a/Lib/multiprocessing/util.py b/Lib/multiprocessing/util.py index 3fe0175..ac9d79e 100644 --- a/Lib/multiprocessing/util.py +++ b/Lib/multiprocessing/util.py @@ -69,34 +69,10 @@ def get_logger(): atexit._exithandlers.remove((_exit_function, (), {})) atexit._exithandlers.append((_exit_function, (), {})) - _check_logger_class() _logger = logging.getLogger(LOGGER_NAME) return _logger -def _check_logger_class(): - ''' - Make sure process name is recorded when loggers are used - ''' - # XXX This function is unnecessary once logging is patched - import logging - if hasattr(logging, 'multiprocessing'): - return - - logging._acquireLock() - try: - OldLoggerClass = logging.getLoggerClass() - if not getattr(OldLoggerClass, '_process_aware', False): - class ProcessAwareLogger(OldLoggerClass): - _process_aware = True - def makeRecord(self, *args, **kwds): - record = OldLoggerClass.makeRecord(self, *args, **kwds) - record.processName = current_process()._name - return record - logging.setLoggerClass(ProcessAwareLogger) - finally: - logging._releaseLock() - def log_to_stderr(level=None): ''' Turn on logging and add a handler which prints to stderr diff --git a/Misc/NEWS b/Misc/NEWS index b88de58..592e1a5 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -132,6 +132,9 @@ Core and Builtins Library ------- +- Issue #4301: Patch the logging module to add processName support, remove + _check_logger_class from multiprocessing. + - Issue #3325: Remove python2.x try: except: imports for old cPickle from multiprocessing. -- cgit v0.12