버전 0.6.0에 추가.
로깅 설정¶
discord.py 는 logging
파이썬 모듈을 사용하여 에러를 기록하고 정보를 디버깅합니다. 로깅 모듈이 설정되지 않은 경우 에러나 경고가 출력되지 않기 때문에 로깅 모듈을 구성하는 것을 강력히 추천합니다. logging
모듈은 다음과 같이 간단하게 구성될 수 있습니다.
import logging
logging.basicConfig(level=logging.INFO)
Placed at the start of the application. This will output the logs from
discord as well as other libraries that use the logging
module
directly to the console.
The optional level
argument specifies what level of events to log
out and can be any of CRITICAL
, ERROR
, WARNING
, INFO
, and
DEBUG
and if not specified defaults to WARNING
.
More advanced setups are possible with the logging
module. For
example to write the logs to a file called discord.log
instead of
outputting them to the console the following snippet can be used:
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 is recommended, especially at verbose levels such as INFO
and DEBUG
, as there are a lot of events logged and it would clog the
stdout of your program.
logging
모듈의 문서와 튜토리얼을 확인하여 더 자세한 정보를 확인하세요.