Logging
Levels
#WARNING is defalut level
import logging

logging.warning('Watch out!')  # will print a message to the console
logging.info('I told you so')  # will not print anything
			
import logging
logging.basicConfig(level=logging.DEBUG);

logging.warning('Watch out!') # will print
logging.info('I told you so') # will print
			
Logging into file
import logging

logging.basicConfig(filename='log.txt', level=logging.DEBUG);

logging.warning('Watch out!')
logging.info('I told you so')
			
Multiple modules
import logging

def doSomething():
    logging.info('Logging in lib ...');
			
import lib
import logging

logging.basicConfig(filename='log.txt', level=logging.DEBUG);

lib.doSomething()
logging.warning('Watch out!')
logging.info('I told you so')
			
Logging format
import logging

logging.basicConfig(format='[%(levelname)s]: %(message)s', level=logging.DEBUG);

logging.warning('Watch out!')
logging.info('I told you so')
			
Reference