Save telegram bot logs in a text file

大城市里の小女人 提交于 2020-03-05 03:16:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!