mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-07 02:08:25 +00:00
Add support for logging.
This commit is contained in:
24
docs/logging.rst
Normal file
24
docs/logging.rst
Normal file
@ -0,0 +1,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
|
Reference in New Issue
Block a user