Home

Tags

logging в python

2010-02-13 python logging

Краткий пример для использования logging.

Инициализация

import logging
logging.basicConfig(filename='file.log',format='%(asctime)s %(levelname)s %(message)s',level=logging.DEBUG)

Добавление сообщений в логи

logging.debug('This is a debug message')
logging.info('This is an info message')
logging.warning('This is a warning message')
logging.error('This is an error message')
logging.critical('This is a critical error message')

Подробный вывод exception'а в логи

try:
    ...
except Exception as e:
    logging.exception(e)