| 1234567891011121314151617181920212223242526272829 |
- import time
- import logging
- from logging.handlers import TimedRotatingFileHandler
- # 创建一个logger
- xp_logger = logging.getLogger('xpLogger')
- xp_logger.setLevel(logging.DEBUG) # 设置日志级别
- # 创建一个handler,用于写入文件,并根据时间自动轮换日志文件
- xp_handler = TimedRotatingFileHandler('log/选品日志', when='midnight', interval=1, backupCount=300)
- xp_handler.setFormatter(logging.Formatter('%(asctime)s - %(message)s'))
- # 添加handler到logger
- xp_logger.addHandler(xp_handler)
- def main():
- try:
- xp_logger.debug('try here')
- while True:
- xp_logger.debug('while here')
- time.sleep(10)
- return # 使用 break 来退出循环,而不是 return
- except Exception as e:
- xp_logger.debug(f'商品发报价信息接口请求--失败: {e}')
- finally:
- xp_logger.debug('finally')
- if __name__ == "__main__":
- main()
|