A
A
anya_hacker2021-10-23 18:29:02
Python
anya_hacker, 2021-10-23 18:29:02

How to set all logging levels in logging python?

How to save in a file not only 1 logging level (in this example, the INFO level, since we configured this at the beginning), but in general everything? Here the debug level is not written to the file. How to record? Together with warning, error and critical?

import logging

logging.basicConfig(
    filename='test.log',
    format='%(name)s %(message)s',
    level=logging.INFO # как задать все уровень логирования, а не только INFO
)

for i in range(10):
    if i < 5:
        logging.info(i)
    else:
        logging.debug(i) # не записывается

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Krostelev, 2021-10-23
@anya_hacker

Info is higher than Debug. When you specify level=logging.INFO, Info and above will be logged.
Change to
level=logging.DEBUG

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question