Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion discord/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
DEALINGS IN THE SOFTWARE.
"""

from __future__ import print_function

from . import endpoints
from .errors import InvalidEventName, InvalidDestination, GatewayNotFound
from .user import User
Expand All @@ -34,6 +36,7 @@
from . import utils
from .invite import Invite

import traceback
import requests
import json, re, time, copy
from collections import deque
Expand Down Expand Up @@ -482,7 +485,8 @@ def _resolve_destination(self, destination):
raise InvalidDestination('Destination must be Channel, PrivateChannel, User, or str')

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
def __getattr__(self, name):
Expand Down
16 changes: 5 additions & 11 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ overriding the specific events. For example: ::


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
Subclassing to listen to events.
Expand All @@ -53,16 +53,10 @@ to handle it, which defaults to log a traceback and ignore the exception.
.. function:: on_error(event, \*args, \*\*kwargs)

Usually when an event raises an uncaught exception, a traceback is
logged and the exception is ignored. If you want to change this
behaviour and handle the exception for whatever reason yourself,
this event can be overridden. Which, when done, will supress the
default logging done.

.. 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.
printed to stderr and the exception is ignored. If you want to
change this behaviour and handle the exception for whatever reason
yourself, this event can be overridden. Which, when done, will
supress the default action of printing the traceback.

The information of the exception rasied and the exception itself can
be retreived with a standard call to ``sys.exc_info()``.
Expand Down
9 changes: 4 additions & 5 deletions docs/logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
Setting Up Logging
===================

*discord.py* logs errors, exceptions, and debug information via the
`logging`_ python module. It is strongly recommended that the logging
module is configured, as no errors or warnings will be output at all if
it is not set up. Configuration of the ``logging`` module can be as
simple as::
*discord.py* logs errors and debug information via the `logging`_ python
module. It is strongly recommended that the logging module is
configured, as no errors or warnings will be output if it is not set up.
Configuration of the ``logging`` module can be as simple as::

import logging

Expand Down