Closes #27904: Improved logging statements to defer formatting until … · bravegnu/cpython@dd917f8 · GitHub
Skip to content

Commit dd917f8

Browse files
committed
Closes python#27904: Improved logging statements to defer formatting until needed.
1 parent ee47e5c commit dd917f8

15 files changed

Lines changed: 25 additions & 26 deletions

File tree

Doc/library/contextlib.rst

Lines changed: 2 additions & 2 deletions

Doc/library/shutil.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ Another example that uses the *ignore* argument to add a logging call::
425425
import logging
426426

427427
def _logpath(path, names):
428-
logging.info('Working in %s' % path)
428+
logging.info('Working in %s', path)
429429
return [] # nothing will be ignored
430430

431431
copytree(source, destination, ignore=_logpath)

Doc/library/typing.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ A user-defined class can be defined as a generic class.
204204
return self.value
205205

206206
def log(self, message: str) -> None:
207-
self.logger.info('{}: {}'.format(self.name, message))
207+
self.logger.info('%s: %s', self.name, message)
208208

209209
``Generic[T]`` as a base class defines that the class ``LoggedVar`` takes a
210210
single type parameter ``T`` . This also makes ``T`` valid as a type within the

Doc/whatsnew/3.2.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,9 +1253,9 @@ definition::
12531253

12541254
@contextmanager
12551255
def track_entry_and_exit(name):
1256-
logging.info('Entering: {}'.format(name))
1256+
logging.info('Entering: %s', name)
12571257
yield
1258-
logging.info('Exiting: {}'.format(name))
1258+
logging.info('Exiting: %s', name)
12591259

12601260
Formerly, this would have only been usable as a context manager::
12611261

Lib/asyncio/base_events.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ def subprocess_shell(self, protocol_factory, cmd, *, stdin=subprocess.PIPE,
10691069
transport = yield from self._make_subprocess_transport(
10701070
protocol, cmd, True, stdin, stdout, stderr, bufsize, **kwargs)
10711071
if self._debug:
1072-
logger.info('%s: %r' % (debug_log, transport))
1072+
logger.info('%s: %r', debug_log, transport)
10731073
return transport, protocol
10741074

10751075
@coroutine
@@ -1099,7 +1099,7 @@ def subprocess_exec(self, protocol_factory, program, *args,
10991099
protocol, popen_args, False, stdin, stdout, stderr,
11001100
bufsize, **kwargs)
11011101
if self._debug:
1102-
logger.info('%s: %r' % (debug_log, transport))
1102+
logger.info('%s: %r', debug_log, transport)
11031103
return transport, protocol
11041104

11051105
def get_exception_handler(self):

Lib/distutils/archive_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def make_zipfile(base_name, base_dir, verbose=0, dry_run=0):
171171
path = os.path.normpath(os.path.join(dirpath, name))
172172
if os.path.isfile(path):
173173
zip.write(path, path)
174-
log.info("adding '%s'" % path)
174+
log.info("adding '%s'", path)
175175
zip.close()
176176

177177
return zip_filename

Lib/distutils/cmd.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,7 @@ def get_sub_commands(self):
329329
# -- External world manipulation -----------------------------------
330330

331331
def warn(self, msg):
332-
log.warn("warning: %s: %s\n" %
333-
(self.get_command_name(), msg))
332+
log.warn("warning: %s: %s\n", self.get_command_name(), msg)
334333

335334
def execute(self, func, args, msg=None, level=1):
336335
util.execute(func, args, msg, dry_run=self.dry_run)

Lib/distutils/command/bdist_dumb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def run(self):
8585
install.skip_build = self.skip_build
8686
install.warn_dir = 0
8787

88-
log.info("installing to %s" % self.bdist_dir)
88+
log.info("installing to %s", self.bdist_dir)
8989
self.run_command('install')
9090

9191
# And make an archive relative to the root of the

Lib/distutils/command/build_ext.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,9 @@ def check_extensions_list(self, extensions):
363363

364364
ext_name, build_info = ext
365365

366-
log.warn(("old-style (ext_name, build_info) tuple found in "
367-
"ext_modules for extension '%s'"
368-
"-- please convert to Extension instance" % ext_name))
366+
log.warn("old-style (ext_name, build_info) tuple found in "
367+
"ext_modules for extension '%s'"
368+
"-- please convert to Extension instance", ext_name)
369369

370370
if not (isinstance(ext_name, str) and
371371
extension_name_re.match(ext_name)):

Lib/distutils/command/config.py

Lines changed: 1 addition & 1 deletion

0 commit comments

Comments
 (0)