1. Module name: logging
2. Usage: import logging
logging.basicConfig(level = logging.DEBUG,format = '%(asctime)s -%(levelname)s - %(message)s')
Put that statement on the first line of the program, but in python's #! line (used to indicate the location of the interpreter, placed below the first line of the program)
Add in the place where you need to print the log:
logging.debug('something to print')
3. Log level (from low to high)
DEBUG: some small details
INFO: some information in the program
WARNING: warning
ERROR: Some events may be affected by errors
CRITCAL: fatal error
After the level is set in basicConfig, the information >= current level will be displayed
4.logging.disable(logging.log level) can disable the corresponding log
5. You can add filename='' to logging, basicConfig() to write the log to the specified file