Answers for "python error log file"

2

python log file

import logging
logging.basicConfig(filename='example.log', encoding='utf-8', level=logging.DEBUG)
logging.debug('This message should go to the log file')
logging.info('So should this')
logging.warning('And this, too')
logging.error('And non-ASCII stuff, too, like Øresund and Malmö')
Posted by: Guest on June-14-2021
0

python logger exception

# Get Python error information with debug output
# logger.exception outputs a stack trace alongside the error message.

# Example

import logging
try:
    1/0
except ZeroDivisionError:
    logging.exception("error_log")
    
# Outputs
    
ERROR:root:error_log
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
ZeroDivisionError: integer division or modulo by zero
Posted by: Guest on August-12-2021

Python Answers by Framework

Browse Popular Code Answers by Language