Logging

Logging is a means of tracking events that happen when some software runs.

Log level
  1. DEBUG Detail information, typically of interest only when diagnosing problems.
  2. INFO Confirmation that things are working as expected
  3. WARNING An indication that something unexpected happened, or indicate of some problem in the near future.
  4. ERROR Due to a more serious problem, the software has not been able to perform some function
  5. 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')
  1. 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)
Logging from multiple modules

results matching ""

    No results matching ""