Logging
Logging is a means of tracking events that happen when some software runs.
Log level
- DEBUG Detail information, typically of interest only when diagnosing problems.
- INFO Confirmation that things are working as expected
- WARNING An indication that something unexpected happened, or indicate of some problem in the near future.
- ERROR Due to a more serious problem, the software has not been able to perform some function
- CRITICAL A serious error, indicating that the program itself may be unable to continue running.
Logging to a file
A very common situation is that of recording logging events in a file.
import logging
logging.basicConfig(filename='exmaple.log', level='logging.DEBUG)
logging.debug('this message should go to the log file')
logging.info('So should this')
- By default, all the log message will be appended to the end of the file. If you want each run to start afresh, you would specify the filemode.
logging.basicConfig(filename='example.log', filename='w', level=logging.DEBUG)