参考官网: https://docs.python.org/zh-cn/3/howto/logging.html
import logging
LOG_FORMAT = ('%(levelname) -10s %(asctime)s %(name) -30s %(funcName) '
'-35s %(lineno) -5d: %(message)s')
LOGGER = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)
if __name__ == '__main__':
LOGGER.info('你好')
LOGGER.error('你好')
LOGGER.debug('你好啊')
LOGGER.warning('你好')
# LOGGER.warn('你好')
###################################################
INFO 2021-05-14 14:14:53,750 __main__ <module> 25 : 你好
ERROR 2021-05-14 14:14:53,750 __main__ <module> 26 : 你好
WARNING 2021-05-14 14:14:53,750 __main__ <module> 28 : 你好
Process finished with exit code 0
################################################
import logging
LOG_FORMAT = "%(asctime)s: %(name)s: %(levelname)s: %(message)s"
LOGGER = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)
if __name__ == '__main__':
LOGGER.info('你好')
LOGGER.error('你好')
LOGGER.debug('你好啊')
LOGGER.warning('你好')