mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-12 08:49:48 +00:00
Defer logging formatting until the logger is actually called.
This would cause unnecessary format calls even if you didn't have logging enabled.
This commit is contained in:
parent
d239cc2666
commit
b06899e7d4
@ -405,7 +405,7 @@ class Client:
|
|||||||
raise
|
raise
|
||||||
|
|
||||||
retry = backoff.delay()
|
retry = backoff.delay()
|
||||||
log.exception("Attempting a reconnect in {:.2f}s".format(retry))
|
log.exception("Attempting a reconnect in %.2fs", retry)
|
||||||
yield from asyncio.sleep(retry, loop=self.loop)
|
yield from asyncio.sleep(retry, loop=self.loop)
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
@ -725,7 +725,7 @@ class Client:
|
|||||||
raise ClientException('event registered must be a coroutine function')
|
raise ClientException('event registered must be a coroutine function')
|
||||||
|
|
||||||
setattr(self, coro.__name__, coro)
|
setattr(self, coro.__name__, coro)
|
||||||
log.info('{0.__name__} has successfully been registered as an event'.format(coro))
|
log.info('%s has successfully been registered as an event', coro.__name__)
|
||||||
return coro
|
return coro
|
||||||
|
|
||||||
def async_event(self, coro):
|
def async_event(self, coro):
|
||||||
|
@ -205,7 +205,7 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
|
|||||||
|
|
||||||
client._connection._update_references(ws)
|
client._connection._update_references(ws)
|
||||||
|
|
||||||
log.info('Created websocket connected to {}'.format(gateway))
|
log.info('Created websocket connected to %s', gateway)
|
||||||
|
|
||||||
# poll event for OP Hello
|
# poll event for OP Hello
|
||||||
yield from ws.poll_event()
|
yield from ws.poll_event()
|
||||||
@ -425,10 +425,10 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
|
|||||||
yield from self.received_message(msg)
|
yield from self.received_message(msg)
|
||||||
except websockets.exceptions.ConnectionClosed as e:
|
except websockets.exceptions.ConnectionClosed as e:
|
||||||
if self._can_handle_close(e.code):
|
if self._can_handle_close(e.code):
|
||||||
log.info('Websocket closed with {0.code} ({0.reason}), attempting a reconnect.'.format(e))
|
log.info('Websocket closed with %s (%s), attempting a reconnect.', e.code, e.reason)
|
||||||
raise ResumeWebSocket(self.shard_id) from e
|
raise ResumeWebSocket(self.shard_id) from e
|
||||||
else:
|
else:
|
||||||
log.info('Websocket closed with {0.code} ({0.reason}), cannot reconnect.'.format(e))
|
log.info('Websocket closed with %s (%s), cannot reconnect.', e.code, e.reason)
|
||||||
raise ConnectionClosed(e, shard_id=self.shard_id) from e
|
raise ConnectionClosed(e, shard_id=self.shard_id) from e
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
@ -646,7 +646,7 @@ class DiscordVoiceWebSocket(websockets.client.WebSocketClientProtocol):
|
|||||||
struct.pack_into('>I', packet, 0, state.ssrc)
|
struct.pack_into('>I', packet, 0, state.ssrc)
|
||||||
state.socket.sendto(packet, (state.endpoint_ip, state.voice_port))
|
state.socket.sendto(packet, (state.endpoint_ip, state.voice_port))
|
||||||
recv = yield from self.loop.sock_recv(state.socket, 70)
|
recv = yield from self.loop.sock_recv(state.socket, 70)
|
||||||
log.debug('received packet in initial_connection: {}'.format(recv))
|
log.debug('received packet in initial_connection: %s', recv)
|
||||||
|
|
||||||
# the ip is ascii starting at the 4th byte and ending at the first null
|
# the ip is ascii starting at the 4th byte and ending at the first null
|
||||||
ip_start = 4
|
ip_start = 4
|
||||||
@ -657,7 +657,7 @@ class DiscordVoiceWebSocket(websockets.client.WebSocketClientProtocol):
|
|||||||
# yes, this is different endianness from everything else
|
# yes, this is different endianness from everything else
|
||||||
state.port = struct.unpack_from('<H', recv, len(recv) - 2)[0]
|
state.port = struct.unpack_from('<H', recv, len(recv) - 2)[0]
|
||||||
|
|
||||||
log.debug('detected ip: {0.ip} port: {0.port}'.format(state))
|
log.debug('detected ip: %s port: %s', state.ip, state.port)
|
||||||
yield from self.select_protocol(state.ip, state.port)
|
yield from self.select_protocol(state.ip, state.port)
|
||||||
log.info('selected the voice protocol for use')
|
log.info('selected the voice protocol for use')
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ class HTTPClient:
|
|||||||
with MaybeUnlock(lock) as maybe_lock:
|
with MaybeUnlock(lock) as maybe_lock:
|
||||||
for tries in range(5):
|
for tries in range(5):
|
||||||
r = yield from self._session.request(method, url, **kwargs)
|
r = yield from self._session.request(method, url, **kwargs)
|
||||||
log.debug(self.REQUEST_LOG.format(method=method, url=url, status=r.status, json=kwargs.get('data')))
|
log.debug('%s %s with %s has returned %s', method, url, kwargs.get('data'), r.status)
|
||||||
try:
|
try:
|
||||||
# even errors have text involved in them so this is safe to call
|
# even errors have text involved in them so this is safe to call
|
||||||
data = yield from json_or_text(r)
|
data = yield from json_or_text(r)
|
||||||
@ -158,28 +158,27 @@ class HTTPClient:
|
|||||||
else:
|
else:
|
||||||
delta = header_bypass_delay
|
delta = header_bypass_delay
|
||||||
|
|
||||||
fmt = 'A rate limit bucket has been exhausted (bucket: {bucket}, retry: {delta}).'
|
log.info('A rate limit bucket has been exhausted (bucket: %s, retry: %s).', bucket, delta)
|
||||||
log.info(fmt.format(bucket=bucket, delta=delta))
|
|
||||||
maybe_lock.defer()
|
maybe_lock.defer()
|
||||||
self.loop.call_later(delta, lock.release)
|
self.loop.call_later(delta, lock.release)
|
||||||
|
|
||||||
# the request was successful so just return the text/json
|
# the request was successful so just return the text/json
|
||||||
if 300 > r.status >= 200:
|
if 300 > r.status >= 200:
|
||||||
log.debug(self.SUCCESS_LOG.format(method=method, url=url, text=data))
|
log.debug('%s %s has received %s', method, url, data)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
# we are being rate limited
|
# we are being rate limited
|
||||||
if r.status == 429:
|
if r.status == 429:
|
||||||
fmt = 'We are being rate limited. Retrying in {:.2} seconds. Handled under the bucket "{}"'
|
fmt = 'We are being rate limited. Retrying in %.2f seconds. Handled under the bucket "%s"'
|
||||||
|
|
||||||
# sleep a bit
|
# sleep a bit
|
||||||
retry_after = data['retry_after'] / 1000.0
|
retry_after = data['retry_after'] / 1000.0
|
||||||
log.info(fmt.format(retry_after, bucket))
|
log.info(fmt, retry_after, bucket)
|
||||||
|
|
||||||
# check if it's a global rate limit
|
# check if it's a global rate limit
|
||||||
is_global = data.get('global', False)
|
is_global = data.get('global', False)
|
||||||
if is_global:
|
if is_global:
|
||||||
log.info('Global rate limit has been hit. Retrying in {:.2} seconds.'.format(retry_after))
|
log.info('Global rate limit has been hit. Retrying in %.2f seconds.', retry_after)
|
||||||
self._global_over.clear()
|
self._global_over.clear()
|
||||||
|
|
||||||
yield from asyncio.sleep(retry_after, loop=self.loop)
|
yield from asyncio.sleep(retry_after, loop=self.loop)
|
||||||
|
@ -149,7 +149,7 @@ class OpusError(DiscordException):
|
|||||||
def __init__(self, code):
|
def __init__(self, code):
|
||||||
self.code = code
|
self.code = code
|
||||||
msg = _lib.opus_strerror(self.code).decode('utf-8')
|
msg = _lib.opus_strerror(self.code).decode('utf-8')
|
||||||
log.info('"{}" has happened'.format(msg))
|
log.info('"%s" has happened', msg)
|
||||||
super().__init__(msg)
|
super().__init__(msg)
|
||||||
|
|
||||||
class OpusNotLoaded(DiscordException):
|
class OpusNotLoaded(DiscordException):
|
||||||
|
@ -265,7 +265,7 @@ class ConnectionState:
|
|||||||
|
|
||||||
# call GUILD_SYNC after we're done chunking
|
# call GUILD_SYNC after we're done chunking
|
||||||
if not self.is_bot:
|
if not self.is_bot:
|
||||||
log.info('Requesting GUILD_SYNC for %s guilds' % len(self.guilds))
|
log.info('Requesting GUILD_SYNC for %s guilds', len(self.guilds))
|
||||||
yield from self.syncer([s.id for s in self.guilds])
|
yield from self.syncer([s.id for s in self.guilds])
|
||||||
except asyncio.CancelledError:
|
except asyncio.CancelledError:
|
||||||
pass
|
pass
|
||||||
|
@ -227,7 +227,6 @@ class VoiceClient:
|
|||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def poll_voice_ws(self, reconnect):
|
def poll_voice_ws(self, reconnect):
|
||||||
backoff = ExponentialBackoff()
|
backoff = ExponentialBackoff()
|
||||||
fmt = 'Disconnected from voice... Reconnecting in {:.2f}s.'
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
yield from self.ws.poll_event()
|
yield from self.ws.poll_event()
|
||||||
@ -242,7 +241,7 @@ class VoiceClient:
|
|||||||
raise e
|
raise e
|
||||||
|
|
||||||
retry = backoff.delay()
|
retry = backoff.delay()
|
||||||
log.exception(fmt.format(retry))
|
log.exception('Disconnected from voice... Reconnecting in %.2fs.', retry)
|
||||||
self._connected.clear()
|
self._connected.clear()
|
||||||
yield from asyncio.sleep(retry, loop=self.loop)
|
yield from asyncio.sleep(retry, loop=self.loop)
|
||||||
yield from self.terminate_handshake()
|
yield from self.terminate_handshake()
|
||||||
@ -417,6 +416,6 @@ class VoiceClient:
|
|||||||
try:
|
try:
|
||||||
self.socket.sendto(packet, (self.endpoint_ip, self.voice_port))
|
self.socket.sendto(packet, (self.endpoint_ip, self.voice_port))
|
||||||
except BlockingIOError:
|
except BlockingIOError:
|
||||||
log.warning('A packet has been dropped (seq: {0.sequence}, timestamp: {0.timestamp})'.format(self))
|
log.warning('A packet has been dropped (seq: %s, timestamp: %s)', self.sequence, self.timestamp)
|
||||||
|
|
||||||
self.checked_add('timestamp', self.encoder.SAMPLES_PER_FRAME, 4294967295)
|
self.checked_add('timestamp', self.encoder.SAMPLES_PER_FRAME, 4294967295)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user