A
A
Andrey Ivanov2022-03-20 20:00:26
Python
Andrey Ivanov, 2022-03-20 20:00:26

Why does the logger not save logs to a file?

I am writing a small bot, I decided to fasten logging to it.
I created a separate module inside, in which I created a logger:

import logging

logging.basicConfig(level='INFO',  filename='Mylogs.log')
MainLogger = logging.getLogger('Admin')


Then I insert the logger into the handlers I need, importing MainLogger from the created module:
@dp.message_handler(CommandStart())
async def greetings_user(message: types.Message):
    from loggmodule import MainLogger
    MainLogger.info(f'{message.from_user.id} подключился к боту')


As a result, the logs are output to the terminal, but are not written to the "MyLogs.log" file, which I specified earlier in the parameters logging.basicConfig. How to fix so that the logging is written to a file, and not displayed in the terminal?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question