问题
A telegram bot I created in python uses pyTelegramBotAPI API. To review logs, I was advised to use this line:
logger = telebot.logger
Now I can see my logs only in the terminal I'm running the bot with and when I close this terminal, the log data is lost.
How can I save this logs to a text file?
回答1:
From what I read in documentation here, it should be possible to use Python's handler to logger.
Have you tried something like this
import logging
logger = telebot.logger
telebot.logger.basicConfig(filename='filename.log', level=logging.DEBUG,
format=' %(asctime)s - %(levelname)s - %(message)s')
来源:https://stackoverflow.com/questions/51741649/save-telegram-bot-logs-in-a-text-file