Understanding logs
If you have written code, you may be familiar with software logs. Software developers use logging to write output from applications to a text file to store different events that happen within the software. They then use these logs to help debug any issues that arise. In Python, you have probably implemented code similar to the following code:
import logging logging.basicConfig(level=0,filename='python-log.log', filemode='w', format='%(levelname)s - %(message)s') logging.debug('Attempted to divide by zero') logging.warning('User left field blank in the form') logging.error('Couldn't find specified file')
The preceding code is a basic logging example that logs different levels – debug
, warning
, and error
– to a file named python-log.log
. The code will produce the following output:
DEBUG - Attempted to divide by zero WARNING - User left field blank in the form ERROR - Couldn&apos...