File tree Expand file tree Collapse file tree 2 files changed +14
-6
lines changed
Expand file tree Collapse file tree 2 files changed +14
-6
lines changed Original file line number Diff line number Diff line change 9494.git
9595__pycache__
9696* .db
97- .vs
97+ .vs
98+
99+ # Keep logrotated files out of git
100+ logs /* .log *
Original file line number Diff line number Diff line change 11# -*- coding: utf-8 -*-
22
3- import logging
3+ import logging . handlers
44import os
55import re
66import sys
2323
2424BOT_TOKEN = "<your_bot_token>"
2525
26- logfile_dir_path = os .path .dirname (os .path .abspath (__file__ ))
27- logfile_abs_path = os .path .join (logfile_dir_path , "logs" , "bot.log" )
28- logfile_handler = logging .FileHandler (logfile_abs_path , 'a' , 'utf-8' )
26+ logdir_path = os .path .dirname (os .path .abspath (__file__ ))
27+ logfile_path = os .path .join (logdir_path , "logs" , "bot.log" )
28+
29+ if not os .path .exists (os .path .join (logdir_path , "logs" )):
30+ os .makedirs (os .path .join (logdir_path , "logs" ))
31+
32+ logfile_handler = logging .handlers .WatchedFileHandler (logfile_path , 'a' , 'utf-8' )
2933
3034logger = logging .getLogger (__name__ )
31- logging .basicConfig (format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' , level = logging .DEBUG , handlers = [logfile_handler ])
35+ logging .basicConfig (format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' , level = logging .INFO , handlers = [logfile_handler ])
3236
3337if not re .match ("[0-9]+:[a-zA-Z0-9\-_]+" , BOT_TOKEN ):
3438 logging .error ("Bot token not correct - please check." )
@@ -463,3 +467,4 @@ def restart(bot, update):
463467
464468updater .start_polling ()
465469updater .idle ()
470+ logger .info ("Bot started" )
You can’t perform that action at this time.
0 commit comments