Skip to content

Commit 1735459

Browse files
committed
feat: Add file logging
1 parent 2dbb22e commit 1735459

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

main.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
DEALINGS IN THE SOFTWARE.
2323
"""
2424

25+
import logging.handlers
2526
import traceback
2627

2728
if __name__ == "__main__":
2829
import asyncio
2930
import os
3031
import json
3132
import sys
33+
import logging
3234

3335
import aiohttp
3436
import discord
@@ -106,6 +108,17 @@ async def runner():
106108

107109
bot.pool = pool
108110

111+
handler = logging.handlers.RotatingFileHandler(
112+
filename='discord.log',
113+
encoding='utf-8',
114+
maxBytes=32 * 1024 * 1024,
115+
backupCount=5,
116+
)
117+
dt_fmt = '%Y-%m-%d %H:%M:%S'
118+
fmt = logging.Formatter('[{asctime}] [{levelname:<8}] {name}: {message}', dt_fmt, style='{')
119+
handler.setFormatter(fmt)
120+
logging.getLogger('discord').addHandler(handler)
121+
109122
discord.utils.setup_logging()
110123

111124
try:

0 commit comments

Comments
 (0)