import logging
logging.basicConfig(level='DEBUG')
logger = logging.getLogger('bunyan')
logger.debug("Looks like rain")
logger.info("And hail")
logging.info("And hail")
logger.warn("Did I hear thunder?")
logger.error("Was that lightning?")
logger.critical("Stop fencing and get inside!")
写入日志文件
import logging
logging.basicConfig(level='DEBUG', filename='blue_ox.log')
logger = logging.getLogger('bunyan')
logger.debug("Looks like rain")
logger.info("And hail")
格式
import logging
fmt = '%(asctime)s %(levelname)s %(lineno)s %(message)s'
logging.basicConfig(level='DEBUG', format=fmt)
logger = logging.getLogger('bunyan')
logger.debug("Looks like rain")
logger.info("And hail")
logging.info("And hail")