aboutsummaryrefslogtreecommitdiff
path: root/docs/logging.rst
blob: 86a31ae726024f23a33d6bcb4ed3f04f444f039f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Setting Up Logging
===================

Newer version of *discord.py* have the capability of logging certain events via the `logging`_ python module.

This is helpful if you want to see certain issues in *discord.py* or want to listen to events yourself.

Setting up logging is fairly simple: ::

    import discord
    import logging

    logger = logging.getLogger('discord')
    logger.setLevel(logging.DEBUG)
    handler = logging.FileHandler(filename='discord.log', encoding='utf-8', mode='w')
    handler.setFormatter(logging.Formatter('%(asctime)s:%(levelname)s:%(name)s: %(message)s'))
    logger.addHandler(handler)

This would create a logger that writes to a file called ``discord.log``. This is recommended as there are a lot of events
logged at a time and it would clog out the stdout of your program.

For more information, check the documentation and tutorial of the `logging`_ module.

.. _logging: https://docs.python.org/2/library/logging.html