Skip to content

Commit e0867cf

Browse files
committed
FIX: Use a WatchedFileHandler to use logrotate
Without this, the bot keeps the file handle of the old file and log rotate doesn't help anything.
1 parent 3bba133 commit e0867cf

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

main.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22

3-
import logging
3+
import logging.handlers
44
import os
55
import re
66
import sys
@@ -25,7 +25,11 @@
2525

2626
logfile_dir_path = os.path.dirname(os.path.abspath(__file__))
2727
logfile_abs_path = os.path.join(logfile_dir_path, "logs", "bot.log")
28-
logfile_handler = logging.FileHandler(logfile_abs_path, 'a', 'utf-8')
28+
29+
if not os.path.exists(os.path.join(logfile_dir_path, "logs")):
30+
os.makedirs(os.path.join(logfile_dir_path, "logs"))
31+
32+
logfile_handler = logging.handlers.WatchedFileHandler(logfile_abs_path, 'a', 'utf-8')
2933

3034
logger = logging.getLogger(__name__)
3135
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.DEBUG, handlers=[logfile_handler])

0 commit comments

Comments
 (0)