import logging
logging.basicConfig(filename='some_log_name.log',level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
try:
5/0
except Exception as e:
logging.error(e)
import logging
# инициализируем логгер как нам надо
logger = logging.getLogger()
try:
variable = 1 / 0
except ZeroDivisionError:
logger.exception("ooops")