]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Merged revisions 68737 via svnmerge from
authorBenjamin Peterson <benjamin@python.org>
Fri, 13 Mar 2009 20:48:10 +0000 (20:48 +0000)
committerBenjamin Peterson <benjamin@python.org>
Fri, 13 Mar 2009 20:48:10 +0000 (20:48 +0000)
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r68737 | jesse.noller | 2009-01-18 15:04:36 -0600 (Sun, 18 Jan 2009) | 1 line

  issue 4301: patch logging to add processName, remove the old _check_logger_class code
........

Lib/logging/__init__.py
Lib/multiprocessing/util.py
Misc/NEWS

index 90fe5816719d28a6dfe76a9debb2784a90ca167c..8c2a38c496c95d55dfd4bf2ba3f2e7bbcf744a9a 100644 (file)
@@ -96,6 +96,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
 #
@@ -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:
index 7d53512725c77bcfcbeba0929ae33d474df2e65d..2e7a2ac2067ab2307af525a91b9899319505e515 100644 (file)
@@ -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
index 8d6b108d01cd1b0fca4306b1fc44d2471a30c1d3..8e0ba6b6f73466bf811c651df26aa76e0c509858 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -658,6 +658,9 @@ Library
 Extension Modules
 -----------------
 
+- Issue #4301: Patch the logging module to add processName support, remove
+  _check_logger_class from multiprocessing.
+
 - Issue #2975: When compiling several extension modules with Visual Studio 2008
   from the same python interpreter, some environment variables would grow
   without limit.