Skip to content

Commit c1d3341

Browse files
committed
TASK: Move logging from stdout to file
1 parent 06120b4 commit c1d3341

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

main.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@
2323

2424
BOT_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, "bot.log")
28+
logfile_handler = logging.FileHandler(logfile_abs_path, 'a', 'utf-8')
29+
2630
logger = logging.getLogger(__name__)
27-
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.DEBUG)
31+
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.DEBUG, handlers=[logfile_handler])
2832

2933
if not re.match("[0-9]+:[a-zA-Z0-9\-_]+", BOT_TOKEN):
3034
logging.error("Bot token not correct - please check.")

0 commit comments

Comments
 (0)