mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 19:34:08 +00:00 
			
		
		
		
	Closes #27904: Improved logging statements to defer formatting until needed.
This commit is contained in:
		
							parent
							
								
									ee47e5cf8a
								
							
						
					
					
						commit
						dd917f84e3
					
				
					 15 changed files with 25 additions and 26 deletions
				
			
		| 
						 | 
					@ -590,10 +590,10 @@ single definition::
 | 
				
			||||||
            self.name = name
 | 
					            self.name = name
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        def __enter__(self):
 | 
					        def __enter__(self):
 | 
				
			||||||
            logging.info('Entering: {}'.format(self.name))
 | 
					            logging.info('Entering: %s', self.name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        def __exit__(self, exc_type, exc, exc_tb):
 | 
					        def __exit__(self, exc_type, exc, exc_tb):
 | 
				
			||||||
            logging.info('Exiting: {}'.format(self.name))
 | 
					            logging.info('Exiting: %s', self.name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Instances of this class can be used as both a context manager::
 | 
					Instances of this class can be used as both a context manager::
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -425,7 +425,7 @@ Another example that uses the *ignore* argument to add a logging call::
 | 
				
			||||||
   import logging
 | 
					   import logging
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   def _logpath(path, names):
 | 
					   def _logpath(path, names):
 | 
				
			||||||
       logging.info('Working in %s' % path)
 | 
					       logging.info('Working in %s', path)
 | 
				
			||||||
       return []   # nothing will be ignored
 | 
					       return []   # nothing will be ignored
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   copytree(source, destination, ignore=_logpath)
 | 
					   copytree(source, destination, ignore=_logpath)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -204,7 +204,7 @@ A user-defined class can be defined as a generic class.
 | 
				
			||||||
           return self.value
 | 
					           return self.value
 | 
				
			||||||
 | 
					
 | 
				
			||||||
       def log(self, message: str) -> None:
 | 
					       def log(self, message: str) -> None:
 | 
				
			||||||
           self.logger.info('{}: {}'.format(self.name, message))
 | 
					           self.logger.info('%s: %s', self.name, message)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
``Generic[T]`` as a base class defines that the class ``LoggedVar`` takes a
 | 
					``Generic[T]`` as a base class defines that the class ``LoggedVar`` takes a
 | 
				
			||||||
single type parameter ``T`` . This also makes ``T`` valid as a type within the
 | 
					single type parameter ``T`` . This also makes ``T`` valid as a type within the
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1253,9 +1253,9 @@ definition::
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @contextmanager
 | 
					    @contextmanager
 | 
				
			||||||
    def track_entry_and_exit(name):
 | 
					    def track_entry_and_exit(name):
 | 
				
			||||||
        logging.info('Entering: {}'.format(name))
 | 
					        logging.info('Entering: %s', name)
 | 
				
			||||||
        yield
 | 
					        yield
 | 
				
			||||||
        logging.info('Exiting: {}'.format(name))
 | 
					        logging.info('Exiting: %s', name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Formerly, this would have only been usable as a context manager::
 | 
					Formerly, this would have only been usable as a context manager::
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1069,7 +1069,7 @@ class BaseEventLoop(events.AbstractEventLoop):
 | 
				
			||||||
        transport = yield from self._make_subprocess_transport(
 | 
					        transport = yield from self._make_subprocess_transport(
 | 
				
			||||||
            protocol, cmd, True, stdin, stdout, stderr, bufsize, **kwargs)
 | 
					            protocol, cmd, True, stdin, stdout, stderr, bufsize, **kwargs)
 | 
				
			||||||
        if self._debug:
 | 
					        if self._debug:
 | 
				
			||||||
            logger.info('%s: %r' % (debug_log, transport))
 | 
					            logger.info('%s: %r', debug_log, transport)
 | 
				
			||||||
        return transport, protocol
 | 
					        return transport, protocol
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @coroutine
 | 
					    @coroutine
 | 
				
			||||||
| 
						 | 
					@ -1099,7 +1099,7 @@ class BaseEventLoop(events.AbstractEventLoop):
 | 
				
			||||||
            protocol, popen_args, False, stdin, stdout, stderr,
 | 
					            protocol, popen_args, False, stdin, stdout, stderr,
 | 
				
			||||||
            bufsize, **kwargs)
 | 
					            bufsize, **kwargs)
 | 
				
			||||||
        if self._debug:
 | 
					        if self._debug:
 | 
				
			||||||
            logger.info('%s: %r' % (debug_log, transport))
 | 
					            logger.info('%s: %r', debug_log, transport)
 | 
				
			||||||
        return transport, protocol
 | 
					        return transport, protocol
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_exception_handler(self):
 | 
					    def get_exception_handler(self):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -171,7 +171,7 @@ def make_zipfile(base_name, base_dir, verbose=0, dry_run=0):
 | 
				
			||||||
                    path = os.path.normpath(os.path.join(dirpath, name))
 | 
					                    path = os.path.normpath(os.path.join(dirpath, name))
 | 
				
			||||||
                    if os.path.isfile(path):
 | 
					                    if os.path.isfile(path):
 | 
				
			||||||
                        zip.write(path, path)
 | 
					                        zip.write(path, path)
 | 
				
			||||||
                        log.info("adding '%s'" % path)
 | 
					                        log.info("adding '%s'", path)
 | 
				
			||||||
            zip.close()
 | 
					            zip.close()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return zip_filename
 | 
					    return zip_filename
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -329,8 +329,7 @@ class Command:
 | 
				
			||||||
    # -- External world manipulation -----------------------------------
 | 
					    # -- External world manipulation -----------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def warn(self, msg):
 | 
					    def warn(self, msg):
 | 
				
			||||||
        log.warn("warning: %s: %s\n" %
 | 
					        log.warn("warning: %s: %s\n", self.get_command_name(), msg)
 | 
				
			||||||
                (self.get_command_name(), msg))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def execute(self, func, args, msg=None, level=1):
 | 
					    def execute(self, func, args, msg=None, level=1):
 | 
				
			||||||
        util.execute(func, args, msg, dry_run=self.dry_run)
 | 
					        util.execute(func, args, msg, dry_run=self.dry_run)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -85,7 +85,7 @@ class bdist_dumb(Command):
 | 
				
			||||||
        install.skip_build = self.skip_build
 | 
					        install.skip_build = self.skip_build
 | 
				
			||||||
        install.warn_dir = 0
 | 
					        install.warn_dir = 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        log.info("installing to %s" % self.bdist_dir)
 | 
					        log.info("installing to %s", self.bdist_dir)
 | 
				
			||||||
        self.run_command('install')
 | 
					        self.run_command('install')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        # And make an archive relative to the root of the
 | 
					        # And make an archive relative to the root of the
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -363,9 +363,9 @@ class build_ext(Command):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            ext_name, build_info = ext
 | 
					            ext_name, build_info = ext
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            log.warn(("old-style (ext_name, build_info) tuple found in "
 | 
					            log.warn("old-style (ext_name, build_info) tuple found in "
 | 
				
			||||||
                     "ext_modules for extension '%s'"
 | 
					                     "ext_modules for extension '%s'"
 | 
				
			||||||
                      "-- please convert to Extension instance" % ext_name))
 | 
					                     "-- please convert to Extension instance", ext_name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if not (isinstance(ext_name, str) and
 | 
					            if not (isinstance(ext_name, str) and
 | 
				
			||||||
                    extension_name_re.match(ext_name)):
 | 
					                    extension_name_re.match(ext_name)):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -337,7 +337,7 @@ def dump_file(filename, head=None):
 | 
				
			||||||
    If head is not None, will be dumped before the file content.
 | 
					    If head is not None, will be dumped before the file content.
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    if head is None:
 | 
					    if head is None:
 | 
				
			||||||
        log.info('%s' % filename)
 | 
					        log.info('%s', filename)
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        log.info(head)
 | 
					        log.info(head)
 | 
				
			||||||
    file = open(filename)
 | 
					    file = open(filename)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -385,7 +385,7 @@ class install(Command):
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                opt_name = opt_name.translate(longopt_xlate)
 | 
					                opt_name = opt_name.translate(longopt_xlate)
 | 
				
			||||||
                val = getattr(self, opt_name)
 | 
					                val = getattr(self, opt_name)
 | 
				
			||||||
            log.debug("  %s: %s" % (opt_name, val))
 | 
					            log.debug("  %s: %s", opt_name, val)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def finalize_unix(self):
 | 
					    def finalize_unix(self):
 | 
				
			||||||
        """Finalizes options for posix platforms."""
 | 
					        """Finalizes options for posix platforms."""
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -94,7 +94,7 @@ class register(PyPIRCCommand):
 | 
				
			||||||
        '''
 | 
					        '''
 | 
				
			||||||
        # send the info to the server and report the result
 | 
					        # send the info to the server and report the result
 | 
				
			||||||
        (code, result) = self.post_to_server(self.build_post_data('verify'))
 | 
					        (code, result) = self.post_to_server(self.build_post_data('verify'))
 | 
				
			||||||
        log.info('Server response (%s): %s' % (code, result))
 | 
					        log.info('Server response (%s): %s', code, result)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def send_metadata(self):
 | 
					    def send_metadata(self):
 | 
				
			||||||
        ''' Send the metadata to the package index server.
 | 
					        ''' Send the metadata to the package index server.
 | 
				
			||||||
| 
						 | 
					@ -205,7 +205,7 @@ Your selection [default 1]: ''', log.INFO)
 | 
				
			||||||
                data['email'] = input('   EMail: ')
 | 
					                data['email'] = input('   EMail: ')
 | 
				
			||||||
            code, result = self.post_to_server(data)
 | 
					            code, result = self.post_to_server(data)
 | 
				
			||||||
            if code != 200:
 | 
					            if code != 200:
 | 
				
			||||||
                log.info('Server response (%s): %s' % (code, result))
 | 
					                log.info('Server response (%s): %s', code, result)
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                log.info('You will receive an email shortly.')
 | 
					                log.info('You will receive an email shortly.')
 | 
				
			||||||
                log.info(('Follow the instructions in it to '
 | 
					                log.info(('Follow the instructions in it to '
 | 
				
			||||||
| 
						 | 
					@ -216,7 +216,7 @@ Your selection [default 1]: ''', log.INFO)
 | 
				
			||||||
            while not data['email']:
 | 
					            while not data['email']:
 | 
				
			||||||
                data['email'] = input('Your email address: ')
 | 
					                data['email'] = input('Your email address: ')
 | 
				
			||||||
            code, result = self.post_to_server(data)
 | 
					            code, result = self.post_to_server(data)
 | 
				
			||||||
            log.info('Server response (%s): %s' % (code, result))
 | 
					            log.info('Server response (%s): %s', code, result)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def build_post_data(self, action):
 | 
					    def build_post_data(self, action):
 | 
				
			||||||
        # figure the data to send - the metadata plus some additional
 | 
					        # figure the data to send - the metadata plus some additional
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -412,7 +412,7 @@ class sdist(Command):
 | 
				
			||||||
            log.info(msg)
 | 
					            log.info(msg)
 | 
				
			||||||
        for file in files:
 | 
					        for file in files:
 | 
				
			||||||
            if not os.path.isfile(file):
 | 
					            if not os.path.isfile(file):
 | 
				
			||||||
                log.warn("'%s' not a regular file -- skipping" % file)
 | 
					                log.warn("'%s' not a regular file -- skipping", file)
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                dest = os.path.join(base_dir, file)
 | 
					                dest = os.path.join(base_dir, file)
 | 
				
			||||||
                self.copy_file(file, dest, link=link)
 | 
					                self.copy_file(file, dest, link=link)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -105,11 +105,11 @@ class BuildSSL:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _subprocess_call(self, cmd, stdout=subprocess.DEVNULL, env=None,
 | 
					    def _subprocess_call(self, cmd, stdout=subprocess.DEVNULL, env=None,
 | 
				
			||||||
                         **kwargs):
 | 
					                         **kwargs):
 | 
				
			||||||
        log.debug("Call '{}'".format(" ".join(cmd)))
 | 
					        log.debug("Call '%s'", " ".join(cmd))
 | 
				
			||||||
        return subprocess.check_call(cmd, stdout=stdout, env=env, **kwargs)
 | 
					        return subprocess.check_call(cmd, stdout=stdout, env=env, **kwargs)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def _subprocess_output(self, cmd, env=None, **kwargs):
 | 
					    def _subprocess_output(self, cmd, env=None, **kwargs):
 | 
				
			||||||
        log.debug("Call '{}'".format(" ".join(cmd)))
 | 
					        log.debug("Call '%s'", " ".join(cmd))
 | 
				
			||||||
        out = subprocess.check_output(cmd, env=env)
 | 
					        out = subprocess.check_output(cmd, env=env)
 | 
				
			||||||
        return out.strip().decode("utf-8")
 | 
					        return out.strip().decode("utf-8")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -168,7 +168,7 @@ class BuildSSL:
 | 
				
			||||||
            if not self.has_src:
 | 
					            if not self.has_src:
 | 
				
			||||||
                self._download_openssl()
 | 
					                self._download_openssl()
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                log.debug("Already has src {}".format(self.src_file))
 | 
					                log.debug("Already has src %s", self.src_file)
 | 
				
			||||||
            self._unpack_openssl()
 | 
					            self._unpack_openssl()
 | 
				
			||||||
            self._build_openssl()
 | 
					            self._build_openssl()
 | 
				
			||||||
            self._install_openssl()
 | 
					            self._install_openssl()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										4
									
								
								setup.py
									
										
									
									
									
								
							
							
						
						
									
										4
									
								
								setup.py
									
										
									
									
									
								
							| 
						 | 
					@ -186,7 +186,7 @@ def find_module_file(module, dirlist):
 | 
				
			||||||
    if not list:
 | 
					    if not list:
 | 
				
			||||||
        return module
 | 
					        return module
 | 
				
			||||||
    if len(list) > 1:
 | 
					    if len(list) > 1:
 | 
				
			||||||
        log.info("WARNING: multiple copies of %s found"%module)
 | 
					        log.info("WARNING: multiple copies of %s found", module)
 | 
				
			||||||
    return os.path.join(list[0], module)
 | 
					    return os.path.join(list[0], module)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class PyBuildExt(build_ext):
 | 
					class PyBuildExt(build_ext):
 | 
				
			||||||
| 
						 | 
					@ -2213,7 +2213,7 @@ class PyBuildScripts(build_scripts):
 | 
				
			||||||
                newfilename = filename + fullversion
 | 
					                newfilename = filename + fullversion
 | 
				
			||||||
            else:
 | 
					            else:
 | 
				
			||||||
                newfilename = filename + minoronly
 | 
					                newfilename = filename + minoronly
 | 
				
			||||||
            log.info('renaming {} to {}'.format(filename, newfilename))
 | 
					            log.info('renaming %s to %s', filename, newfilename)
 | 
				
			||||||
            os.rename(filename, newfilename)
 | 
					            os.rename(filename, newfilename)
 | 
				
			||||||
            newoutfiles.append(newfilename)
 | 
					            newoutfiles.append(newfilename)
 | 
				
			||||||
            if filename in updated_files:
 | 
					            if filename in updated_files:
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue