guygrinberger
guygrinberger

Reputation: 327

Save telegram bot logs in a text file

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?

Upvotes: 2

Views: 7143

Answers (1)

Ochmar
Ochmar

Reputation: 294

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')

Upvotes: 3

Related Questions