Rename the logger to plain "logger".
diff --git a/Lib/asyncio/base_events.py b/Lib/asyncio/base_events.py
index 32457eb..5f1bff7 100644
--- a/Lib/asyncio/base_events.py
+++ b/Lib/asyncio/base_events.py
@@ -27,7 +27,7 @@
from . import events
from . import futures
from . import tasks
-from .log import asyncio_log
+from .log import logger
__all__ = ['BaseEventLoop', 'Server']
@@ -580,7 +580,7 @@
level = logging.INFO
else:
level = logging.DEBUG
- asyncio_log.log(level, 'poll%s took %.3f seconds', argstr, t1-t0)
+ logger.log(level, 'poll%s took %.3f seconds', argstr, t1-t0)
self._process_events(event_list)
# Handle 'later' callbacks that are ready.
diff --git a/Lib/asyncio/events.py b/Lib/asyncio/events.py
index 9724615..6ca5668 100644
--- a/Lib/asyncio/events.py
+++ b/Lib/asyncio/events.py
@@ -12,7 +12,7 @@
import threading
import socket
-from .log import asyncio_log
+from .log import logger
class Handle:
@@ -36,8 +36,8 @@
try:
self._callback(*self._args)
except Exception:
- asyncio_log.exception('Exception in callback %s %r',
- self._callback, self._args)
+ logger.exception('Exception in callback %s %r',
+ self._callback, self._args)
self = None # Needed to break cycles when an exception occurs.
diff --git a/Lib/asyncio/futures.py b/Lib/asyncio/futures.py
index 99a043b..db27838 100644
--- a/Lib/asyncio/futures.py
+++ b/Lib/asyncio/futures.py
@@ -10,7 +10,7 @@
import traceback
from . import events
-from .log import asyncio_log
+from .log import logger
# States for Future.
_PENDING = 'PENDING'
@@ -99,8 +99,8 @@
def __del__(self):
if self.tb:
- asyncio_log.error('Future/Task exception was never retrieved:\n%s',
- ''.join(self.tb))
+ logger.error('Future/Task exception was never retrieved:\n%s',
+ ''.join(self.tb))
class Future:
diff --git a/Lib/asyncio/log.py b/Lib/asyncio/log.py
index 54dc784..23a7074 100644
--- a/Lib/asyncio/log.py
+++ b/Lib/asyncio/log.py
@@ -3,4 +3,5 @@
import logging
-asyncio_log = logging.getLogger("asyncio")
+# Name the logger after the package.
+logger = logging.getLogger(__package__)
diff --git a/Lib/asyncio/proactor_events.py b/Lib/asyncio/proactor_events.py
index 348de03..c1347b7 100644
--- a/Lib/asyncio/proactor_events.py
+++ b/Lib/asyncio/proactor_events.py
@@ -10,7 +10,7 @@
from . import constants
from . import futures
from . import transports
-from .log import asyncio_log
+from .log import logger
class _ProactorBasePipeTransport(transports.BaseTransport):
@@ -50,7 +50,7 @@
self._read_fut.cancel()
def _fatal_error(self, exc):
- asyncio_log.exception('Fatal error for %s', self)
+ logger.exception('Fatal error for %s', self)
self._force_close(exc)
def _force_close(self, exc):
@@ -164,7 +164,7 @@
if self._conn_lost:
if self._conn_lost >= constants.LOG_THRESHOLD_FOR_CONNLOST_WRITES:
- asyncio_log.warning('socket.send() raised exception.')
+ logger.warning('socket.send() raised exception.')
self._conn_lost += 1
return
self._buffer.append(data)
@@ -246,7 +246,7 @@
def __init__(self, proactor):
super().__init__()
- asyncio_log.debug('Using proactor: %s', proactor.__class__.__name__)
+ logger.debug('Using proactor: %s', proactor.__class__.__name__)
self._proactor = proactor
self._selector = proactor # convenient alias
proactor.set_loop(self)
@@ -335,7 +335,7 @@
f = self._proactor.accept(sock)
except OSError:
if sock.fileno() != -1:
- asyncio_log.exception('Accept failed')
+ logger.exception('Accept failed')
sock.close()
except futures.CancelledError:
sock.close()
diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py
index bae9a49..e8ae885 100644
--- a/Lib/asyncio/selector_events.py
+++ b/Lib/asyncio/selector_events.py
@@ -17,7 +17,7 @@
from . import futures
from . import selectors
from . import transports
-from .log import asyncio_log
+from .log import logger
class BaseSelectorEventLoop(base_events.BaseEventLoop):
@@ -31,7 +31,7 @@
if selector is None:
selector = selectors.DefaultSelector()
- asyncio_log.debug('Using selector: %s', selector.__class__.__name__)
+ logger.debug('Using selector: %s', selector.__class__.__name__)
self._selector = selector
self._make_self_pipe()
@@ -105,7 +105,7 @@
sock.close()
# There's nowhere to send the error, so just log it.
# TODO: Someone will want an error handler for this.
- asyncio_log.exception('Accept failed')
+ logger.exception('Accept failed')
else:
if ssl:
self._make_ssl_transport(
@@ -363,7 +363,7 @@
def _fatal_error(self, exc):
# should be called from exception handler only
- asyncio_log.exception('Fatal error for %s', self)
+ logger.exception('Fatal error for %s', self)
self._force_close(exc)
def _force_close(self, exc):
@@ -444,7 +444,7 @@
if self._conn_lost:
if self._conn_lost >= constants.LOG_THRESHOLD_FOR_CONNLOST_WRITES:
- asyncio_log.warning('socket.send() raised exception.')
+ logger.warning('socket.send() raised exception.')
self._conn_lost += 1
return
@@ -667,7 +667,7 @@
if self._conn_lost:
if self._conn_lost >= constants.LOG_THRESHOLD_FOR_CONNLOST_WRITES:
- asyncio_log.warning('socket.send() raised exception.')
+ logger.warning('socket.send() raised exception.')
self._conn_lost += 1
return
@@ -714,7 +714,7 @@
if self._conn_lost and self._address:
if self._conn_lost >= constants.LOG_THRESHOLD_FOR_CONNLOST_WRITES:
- asyncio_log.warning('socket.send() raised exception.')
+ logger.warning('socket.send() raised exception.')
self._conn_lost += 1
return
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py
index 2c8579f..6385017 100644
--- a/Lib/asyncio/tasks.py
+++ b/Lib/asyncio/tasks.py
@@ -16,7 +16,7 @@
from . import events
from . import futures
-from .log import asyncio_log
+from .log import logger
# If you set _DEBUG to true, @coroutine will wrap the resulting
# generator objects in a CoroWrapper instance (defined below). That
@@ -62,8 +62,8 @@
code = func.__code__
filename = code.co_filename
lineno = code.co_firstlineno
- asyncio_log.error('Coroutine %r defined at %s:%s was never yielded from',
- func.__name__, filename, lineno)
+ logger.error('Coroutine %r defined at %s:%s was never yielded from',
+ func.__name__, filename, lineno)
def coroutine(func):
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py
index a3a8e11..34b2aea 100644
--- a/Lib/asyncio/unix_events.py
+++ b/Lib/asyncio/unix_events.py
@@ -18,7 +18,7 @@
from . import selector_events
from . import tasks
from . import transports
-from .log import asyncio_log
+from .log import logger
__all__ = ['SelectorEventLoop', 'STDIN', 'STDOUT', 'STDERR']
@@ -79,7 +79,7 @@
try:
signal.set_wakeup_fd(-1)
except ValueError as nexc:
- asyncio_log.info('set_wakeup_fd(-1) failed: %s', nexc)
+ logger.info('set_wakeup_fd(-1) failed: %s', nexc)
if exc.errno == errno.EINVAL:
raise RuntimeError('sig {} cannot be caught'.format(sig))
@@ -124,7 +124,7 @@
try:
signal.set_wakeup_fd(-1)
except ValueError as exc:
- asyncio_log.info('set_wakeup_fd(-1) failed: %s', exc)
+ logger.info('set_wakeup_fd(-1) failed: %s', exc)
return True
@@ -185,7 +185,7 @@
if transp is not None:
transp._process_exited(returncode)
except Exception:
- asyncio_log.exception('Unknown exception in SIGCHLD handler')
+ logger.exception('Unknown exception in SIGCHLD handler')
def _subprocess_closed(self, transport):
pid = transport.get_pid()
@@ -244,7 +244,7 @@
def _fatal_error(self, exc):
# should be called by exception handler only
- asyncio_log.exception('Fatal error for %s', self)
+ logger.exception('Fatal error for %s', self)
self._close(exc)
def _close(self, exc):
@@ -294,8 +294,8 @@
if self._conn_lost or self._closing:
if self._conn_lost >= constants.LOG_THRESHOLD_FOR_CONNLOST_WRITES:
- asyncio_log.warning('pipe closed by peer or '
- 'os.write(pipe, data) raised exception.')
+ logger.warning('pipe closed by peer or '
+ 'os.write(pipe, data) raised exception.')
self._conn_lost += 1
return
@@ -369,7 +369,7 @@
def _fatal_error(self, exc):
# should be called by exception handler only
- asyncio_log.exception('Fatal error for %s', self)
+ logger.exception('Fatal error for %s', self)
self._close(exc)
def _close(self, exc=None):
diff --git a/Lib/asyncio/windows_events.py b/Lib/asyncio/windows_events.py
index 1d0ad26..bbeada8 100644
--- a/Lib/asyncio/windows_events.py
+++ b/Lib/asyncio/windows_events.py
@@ -11,7 +11,7 @@
from . import selector_events
from . import tasks
from . import windows_utils
-from .log import asyncio_log
+from .log import logger
try:
import _overlapped
@@ -139,7 +139,7 @@
f = self._proactor.accept_pipe(pipe)
except OSError:
if pipe and pipe.fileno() != -1:
- asyncio_log.exception('Pipe accept failed')
+ logger.exception('Pipe accept failed')
pipe.close()
except futures.CancelledError:
if pipe:
@@ -367,7 +367,7 @@
while self._cache:
if not self._poll(1):
- asyncio_log.debug('taking long time to close proactor')
+ logger.debug('taking long time to close proactor')
self._results = []
if self._iocp is not None:
diff --git a/Lib/test/test_asyncio/test_base_events.py b/Lib/test/test_asyncio/test_base_events.py
index d48d12c..e62f476 100644
--- a/Lib/test/test_asyncio/test_base_events.py
+++ b/Lib/test/test_asyncio/test_base_events.py
@@ -183,7 +183,7 @@
self.assertTrue(self.loop._process_events.called)
@unittest.mock.patch('asyncio.base_events.time')
- @unittest.mock.patch('asyncio.base_events.asyncio_log')
+ @unittest.mock.patch('asyncio.base_events.logger')
def test__run_once_logging(self, m_logging, m_time):
# Log to INFO level if timeout > 1.0 sec.
idx = -1
@@ -579,7 +579,7 @@
self.loop._accept_connection(MyProto, sock)
self.assertFalse(sock.close.called)
- @unittest.mock.patch('asyncio.selector_events.asyncio_log')
+ @unittest.mock.patch('asyncio.selector_events.logger')
def test_accept_connection_exception(self, m_log):
sock = unittest.mock.Mock()
sock.fileno.return_value = 10
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
index 243f400..a9a9271 100644
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -1320,7 +1320,7 @@
self.assertRaises(
AssertionError, events.make_handle, h1, ())
- @unittest.mock.patch('asyncio.events.asyncio_log')
+ @unittest.mock.patch('asyncio.events.logger')
def test_callback_with_exception(self, log):
def callback():
raise ValueError()
diff --git a/Lib/test/test_asyncio/test_futures.py b/Lib/test/test_asyncio/test_futures.py
index 9b5108c..ccea2ff 100644
--- a/Lib/test/test_asyncio/test_futures.py
+++ b/Lib/test/test_asyncio/test_futures.py
@@ -170,20 +170,20 @@
self.assertRaises(AssertionError, test)
fut.cancel()
- @unittest.mock.patch('asyncio.futures.asyncio_log')
+ @unittest.mock.patch('asyncio.futures.logger')
def test_tb_logger_abandoned(self, m_log):
fut = futures.Future(loop=self.loop)
del fut
self.assertFalse(m_log.error.called)
- @unittest.mock.patch('asyncio.futures.asyncio_log')
+ @unittest.mock.patch('asyncio.futures.logger')
def test_tb_logger_result_unretrieved(self, m_log):
fut = futures.Future(loop=self.loop)
fut.set_result(42)
del fut
self.assertFalse(m_log.error.called)
- @unittest.mock.patch('asyncio.futures.asyncio_log')
+ @unittest.mock.patch('asyncio.futures.logger')
def test_tb_logger_result_retrieved(self, m_log):
fut = futures.Future(loop=self.loop)
fut.set_result(42)
@@ -191,7 +191,7 @@
del fut
self.assertFalse(m_log.error.called)
- @unittest.mock.patch('asyncio.futures.asyncio_log')
+ @unittest.mock.patch('asyncio.futures.logger')
def test_tb_logger_exception_unretrieved(self, m_log):
fut = futures.Future(loop=self.loop)
fut.set_exception(RuntimeError('boom'))
@@ -199,7 +199,7 @@
test_utils.run_briefly(self.loop)
self.assertTrue(m_log.error.called)
- @unittest.mock.patch('asyncio.futures.asyncio_log')
+ @unittest.mock.patch('asyncio.futures.logger')
def test_tb_logger_exception_retrieved(self, m_log):
fut = futures.Future(loop=self.loop)
fut.set_exception(RuntimeError('boom'))
@@ -207,7 +207,7 @@
del fut
self.assertFalse(m_log.error.called)
- @unittest.mock.patch('asyncio.futures.asyncio_log')
+ @unittest.mock.patch('asyncio.futures.logger')
def test_tb_logger_exception_result_retrieved(self, m_log):
fut = futures.Future(loop=self.loop)
fut.set_exception(RuntimeError('boom'))
diff --git a/Lib/test/test_asyncio/test_proactor_events.py b/Lib/test/test_asyncio/test_proactor_events.py
index c52ade0..e4dd609 100644
--- a/Lib/test/test_asyncio/test_proactor_events.py
+++ b/Lib/test/test_asyncio/test_proactor_events.py
@@ -135,7 +135,7 @@
self.loop._proactor.send.return_value.add_done_callback.\
assert_called_with(tr._loop_writing)
- @unittest.mock.patch('asyncio.proactor_events.asyncio_log')
+ @unittest.mock.patch('asyncio.proactor_events.logger')
def test_loop_writing_err(self, m_log):
err = self.loop._proactor.send.side_effect = OSError()
tr = _ProactorSocketTransport(self.loop, self.sock, self.protocol)
@@ -207,7 +207,7 @@
test_utils.run_briefly(self.loop)
self.assertFalse(self.protocol.connection_lost.called)
- @unittest.mock.patch('asyncio.proactor_events.asyncio_log')
+ @unittest.mock.patch('asyncio.proactor_events.logger')
def test_fatal_error(self, m_logging):
tr = _ProactorSocketTransport(self.loop, self.sock, self.protocol)
tr._force_close = unittest.mock.Mock()
@@ -432,7 +432,7 @@
def test_process_events(self):
self.loop._process_events([])
- @unittest.mock.patch('asyncio.proactor_events.asyncio_log')
+ @unittest.mock.patch('asyncio.proactor_events.logger')
def test_create_server(self, m_log):
pf = unittest.mock.Mock()
call_soon = self.loop.call_soon = unittest.mock.Mock()
diff --git a/Lib/test/test_asyncio/test_selector_events.py b/Lib/test/test_asyncio/test_selector_events.py
index 0225e13..1465cd2 100644
--- a/Lib/test/test_asyncio/test_selector_events.py
+++ b/Lib/test/test_asyncio/test_selector_events.py
@@ -626,7 +626,7 @@
self.assertFalse(self.loop.readers)
self.assertEqual(1, self.loop.remove_reader_count[7])
- @unittest.mock.patch('asyncio.log.asyncio_log.exception')
+ @unittest.mock.patch('asyncio.log.logger.exception')
def test_fatal_error(self, m_exc):
exc = OSError()
tr = _SelectorTransport(self.loop, self.sock, self.protocol, None)
@@ -823,7 +823,7 @@
self.loop.assert_writer(7, transport._write_ready)
self.assertEqual(collections.deque([b'data']), transport._buffer)
- @unittest.mock.patch('asyncio.selector_events.asyncio_log')
+ @unittest.mock.patch('asyncio.selector_events.logger')
def test_write_exception(self, m_log):
err = self.sock.send.side_effect = OSError()
@@ -937,7 +937,7 @@
transport._write_ready()
transport._fatal_error.assert_called_with(err)
- @unittest.mock.patch('asyncio.selector_events.asyncio_log')
+ @unittest.mock.patch('asyncio.selector_events.logger')
def test_write_ready_exception_and_close(self, m_log):
self.sock.send.side_effect = OSError()
remove_writer = self.loop.remove_writer = unittest.mock.Mock()
@@ -1072,7 +1072,7 @@
transport.write(b'data')
self.assertEqual(transport._conn_lost, 2)
- @unittest.mock.patch('asyncio.selector_events.asyncio_log')
+ @unittest.mock.patch('asyncio.selector_events.logger')
def test_write_exception(self, m_log):
transport = self._make_one()
transport._conn_lost = 1
@@ -1325,7 +1325,7 @@
self.assertEqual(
[(b'data', ('0.0.0.0', 12345))], list(transport._buffer))
- @unittest.mock.patch('asyncio.selector_events.asyncio_log')
+ @unittest.mock.patch('asyncio.selector_events.logger')
def test_sendto_exception(self, m_log):
data = b'data'
err = self.sock.sendto.side_effect = OSError()
@@ -1475,7 +1475,7 @@
self.assertTrue(transport._fatal_error.called)
- @unittest.mock.patch('asyncio.log.asyncio_log.exception')
+ @unittest.mock.patch('asyncio.log.logger.exception')
def test_fatal_error_connected(self, m_exc):
transport = _SelectorDatagramTransport(
self.loop, self.sock, self.protocol, ('0.0.0.0', 1))
diff --git a/Lib/test/test_asyncio/test_unix_events.py b/Lib/test/test_asyncio/test_unix_events.py
index 6dbd47f..227366d 100644
--- a/Lib/test/test_asyncio/test_unix_events.py
+++ b/Lib/test/test_asyncio/test_unix_events.py
@@ -87,7 +87,7 @@
signal.SIGINT, lambda: True)
@unittest.mock.patch('asyncio.unix_events.signal')
- @unittest.mock.patch('asyncio.unix_events.asyncio_log')
+ @unittest.mock.patch('asyncio.unix_events.logger')
def test_add_signal_handler_install_error2(self, m_logging, m_signal):
m_signal.NSIG = signal.NSIG
@@ -104,7 +104,7 @@
self.assertEqual(1, m_signal.set_wakeup_fd.call_count)
@unittest.mock.patch('asyncio.unix_events.signal')
- @unittest.mock.patch('asyncio.unix_events.asyncio_log')
+ @unittest.mock.patch('asyncio.unix_events.logger')
def test_add_signal_handler_install_error3(self, m_logging, m_signal):
class Err(OSError):
errno = errno.EINVAL
@@ -149,7 +149,7 @@
m_signal.signal.call_args[0])
@unittest.mock.patch('asyncio.unix_events.signal')
- @unittest.mock.patch('asyncio.unix_events.asyncio_log')
+ @unittest.mock.patch('asyncio.unix_events.logger')
def test_remove_signal_handler_cleanup_error(self, m_logging, m_signal):
m_signal.NSIG = signal.NSIG
self.loop.add_signal_handler(signal.SIGHUP, lambda: True)
@@ -270,7 +270,7 @@
self.assertFalse(m_WEXITSTATUS.called)
self.assertFalse(m_WTERMSIG.called)
- @unittest.mock.patch('asyncio.unix_events.asyncio_log')
+ @unittest.mock.patch('asyncio.unix_events.logger')
@unittest.mock.patch('os.WTERMSIG')
@unittest.mock.patch('os.WEXITSTATUS')
@unittest.mock.patch('os.WIFSIGNALED')
@@ -360,7 +360,7 @@
test_utils.run_briefly(self.loop)
self.assertFalse(self.protocol.data_received.called)
- @unittest.mock.patch('asyncio.log.asyncio_log.exception')
+ @unittest.mock.patch('asyncio.log.logger.exception')
@unittest.mock.patch('os.read')
def test__read_ready_error(self, m_read, m_logexc):
tr = unix_events._UnixReadPipeTransport(
@@ -550,7 +550,7 @@
self.loop.assert_writer(5, tr._write_ready)
self.assertEqual([b'data'], tr._buffer)
- @unittest.mock.patch('asyncio.unix_events.asyncio_log')
+ @unittest.mock.patch('asyncio.unix_events.logger')
@unittest.mock.patch('os.write')
def test_write_err(self, m_write, m_log):
tr = unix_events._UnixWritePipeTransport(
@@ -648,7 +648,7 @@
self.loop.assert_writer(5, tr._write_ready)
self.assertEqual([b'data'], tr._buffer)
- @unittest.mock.patch('asyncio.log.asyncio_log.exception')
+ @unittest.mock.patch('asyncio.log.logger.exception')
@unittest.mock.patch('os.write')
def test__write_ready_err(self, m_write, m_logexc):
tr = unix_events._UnixWritePipeTransport(