Python中如何使用logging模块进行日志记录?

2026-05-21 16:151阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计117个文字,预计阅读时间需要1分钟。

Python中如何使用logging模块进行日志记录?

pythonimport logging

logging.basicConfig( level=logging.ERROR, format='%(asctime)s [%(levelname)s] [%(filename)s:%(lineno)d] %(message)s', datefmt='%a, %d %b %Y %H:%M:%S', filename='/tmp/test.log', filemode='w')

logging.debug('debug')

import logging
logging.basicConfig(level=logging.ERROR,
format='%(asctime)s filename=%(filename)s [line:%(lineno)d] %(levelname)s %(message)s',
datefmt='a, %d %b %Y %H:%M:%S',
filename='d:/tmp/test.log',
filemode='w',
)
logging.debug('debug message1')
logging.info('info message2')
logging.warning('warning message3')
logging.error('error message4')
logging.critical('critical message5')

Python中如何使用logging模块进行日志记录?



本文共计117个文字,预计阅读时间需要1分钟。

Python中如何使用logging模块进行日志记录?

pythonimport logging

logging.basicConfig( level=logging.ERROR, format='%(asctime)s [%(levelname)s] [%(filename)s:%(lineno)d] %(message)s', datefmt='%a, %d %b %Y %H:%M:%S', filename='/tmp/test.log', filemode='w')

logging.debug('debug')

import logging
logging.basicConfig(level=logging.ERROR,
format='%(asctime)s filename=%(filename)s [line:%(lineno)d] %(levelname)s %(message)s',
datefmt='a, %d %b %Y %H:%M:%S',
filename='d:/tmp/test.log',
filemode='w',
)
logging.debug('debug message1')
logging.info('info message2')
logging.warning('warning message3')
logging.error('error message4')
logging.critical('critical message5')

Python中如何使用logging模块进行日志记录?