import logging logging.basicConfig(level=logging.WARNING, format='%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s') logging.info('this is a loggging info message') logging.debug('this is a loggging debug message') logging.warning('this is loggging a warning message') logging.error('this is an loggging error message') logging.critical('this is a loggging critical message')
logging.info('this is a loggging info message') logging.debug('this is a loggging debug message') logging.warning('this is loggging a warning message') logging.error('this is an loggging error message') logging.critical('this is a loggging critical message')
# log.txt # 2018-09-17 14:45:22,340 - other.py[line:20] - WARNING: this is loggging a warning message # 2018-09-17 14:45:22,341 - other.py[line:21] - ERROR: this is an loggging error message # 2018-09-17 14:45:22,341 - other.py[line:22] - CRITICAL: this is a loggging critical message
# 日志 logger.debug('this is a logger debug message') logger.info('this is a logger info message') logger.warning('this is a logger warning message') logger.error('this is a logger error message') logger.critical('this is a logger critical message')