mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-17 03:09:05 +00:00
Print to stderr in on_error
Apparently the clever hack for logging in on_error was not so clever after all. If logging isn't configured, by the logging modules definition of not configured, which is root logger not having an Handlers attached, it will call logging.basicConfig(). Which messes up setups that define handlers for other loggers than the root logger. Going directly to the root logger rather than using the broken convenience methods for logger is not an option either, as logger before Python 3.2 does not have lastResort on the root logger, and prints an error when invoked without any handlers. Resolve by printing tracebacks to stderr by default in on_error.
This commit is contained in:
parent
b9c40955ab
commit
320cd39b6a
@ -24,6 +24,8 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|||||||
DEALINGS IN THE SOFTWARE.
|
DEALINGS IN THE SOFTWARE.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
from . import endpoints
|
from . import endpoints
|
||||||
from .errors import InvalidEventName, InvalidDestination, GatewayNotFound
|
from .errors import InvalidEventName, InvalidDestination, GatewayNotFound
|
||||||
from .user import User
|
from .user import User
|
||||||
@ -34,6 +36,7 @@ from .message import Message
|
|||||||
from . import utils
|
from . import utils
|
||||||
from .invite import Invite
|
from .invite import Invite
|
||||||
|
|
||||||
|
import traceback
|
||||||
import requests
|
import requests
|
||||||
import json, re, time, copy
|
import json, re, time, copy
|
||||||
from collections import deque
|
from collections import deque
|
||||||
@ -482,7 +485,8 @@ class Client(object):
|
|||||||
raise InvalidDestination('Destination must be Channel, PrivateChannel, User, or str')
|
raise InvalidDestination('Destination must be Channel, PrivateChannel, User, or str')
|
||||||
|
|
||||||
def on_error(self, event_method, *args, **kwargs):
|
def on_error(self, event_method, *args, **kwargs):
|
||||||
logging.exception('Ignoring exception in {}'.format(event_method))
|
print('Ignoring exception in {}'.format(event_method), file=sys.stderr)
|
||||||
|
traceback.print_exc()
|
||||||
|
|
||||||
# Compatibility shim
|
# Compatibility shim
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
|
16
docs/api.rst
16
docs/api.rst
@ -39,7 +39,7 @@ overriding the specific events. For example: ::
|
|||||||
|
|
||||||
|
|
||||||
If an event handler raises an exception, :func:`on_error` will be called
|
If an event handler raises an exception, :func:`on_error` will be called
|
||||||
to handle it, which defaults to log a traceback and ignore the exception.
|
to handle it, which defaults to print a traceback and ignore the exception.
|
||||||
|
|
||||||
.. versionadded:: 0.7.0
|
.. versionadded:: 0.7.0
|
||||||
Subclassing to listen to events.
|
Subclassing to listen to events.
|
||||||
@ -53,16 +53,10 @@ to handle it, which defaults to log a traceback and ignore the exception.
|
|||||||
.. function:: on_error(event, \*args, \*\*kwargs)
|
.. function:: on_error(event, \*args, \*\*kwargs)
|
||||||
|
|
||||||
Usually when an event raises an uncaught exception, a traceback is
|
Usually when an event raises an uncaught exception, a traceback is
|
||||||
logged and the exception is ignored. If you want to change this
|
printed to stderr and the exception is ignored. If you want to
|
||||||
behaviour and handle the exception for whatever reason yourself,
|
change this behaviour and handle the exception for whatever reason
|
||||||
this event can be overridden. Which, when done, will supress the
|
yourself, this event can be overridden. Which, when done, will
|
||||||
default logging done.
|
supress the default action of printing the traceback.
|
||||||
|
|
||||||
.. note::
|
|
||||||
|
|
||||||
The default ``on_error`` handler logs exception to the root logger
|
|
||||||
instead of a logger under the discord namespace. This is to ensure
|
|
||||||
that exceptions are output somewhere if logging is not configured.
|
|
||||||
|
|
||||||
The information of the exception rasied and the exception itself can
|
The information of the exception rasied and the exception itself can
|
||||||
be retreived with a standard call to ``sys.exc_info()``.
|
be retreived with a standard call to ``sys.exc_info()``.
|
||||||
|
@ -4,11 +4,10 @@
|
|||||||
Setting Up Logging
|
Setting Up Logging
|
||||||
===================
|
===================
|
||||||
|
|
||||||
*discord.py* logs errors, exceptions, and debug information via the
|
*discord.py* logs errors and debug information via the `logging`_ python
|
||||||
`logging`_ python module. It is strongly recommended that the logging
|
module. It is strongly recommended that the logging module is
|
||||||
module is configured, as no errors or warnings will be output at all if
|
configured, as no errors or warnings will be output if it is not set up.
|
||||||
it is not set up. Configuration of the ``logging`` module can be as
|
Configuration of the ``logging`` module can be as simple as::
|
||||||
simple as::
|
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user