[Python-checkins] r68740 - in python/branches/py3k: Lib/logging/__init__.py Lib/multiprocessing/util.py Misc/NEWS

jesse.noller python-checkins at python.org
Sun Jan 18 22:12:59 CET 2009


Author: jesse.noller
Date: Sun Jan 18 22:12:58 2009
New Revision: 68740

Log:
merge cl r68737 to py3k

Modified:
   python/branches/py3k/   (props changed)
   python/branches/py3k/Lib/logging/__init__.py
   python/branches/py3k/Lib/multiprocessing/util.py
   python/branches/py3k/Misc/NEWS

Modified: python/branches/py3k/Lib/logging/__init__.py
==============================================================================
--- python/branches/py3k/Lib/logging/__init__.py	(original)
+++ python/branches/py3k/Lib/logging/__init__.py	Sun Jan 18 22:12:58 2009
@@ -99,6 +99,11 @@
 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 @@
         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:

Modified: python/branches/py3k/Lib/multiprocessing/util.py
==============================================================================
--- python/branches/py3k/Lib/multiprocessing/util.py	(original)
+++ python/branches/py3k/Lib/multiprocessing/util.py	Sun Jan 18 22:12:58 2009
@@ -69,34 +69,10 @@
             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

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Sun Jan 18 22:12:58 2009
@@ -132,6 +132,9 @@
 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. 
 


More information about the Python-checkins mailing list