TA的每日心情 | 无聊 4 天前 |
---|
签到天数: 530 天 连续签到: 2 天 [LV.9]测试副司令
|
1测试积点
- def __init__(self):
- self.logger = logging.getLogger()
- self.logger.setLevel(logging.DEBUG)
- # 2.将log信息输出到log文件中
- # 2.1 先定位看将log文件输出到哪里去
- current_dir = os.path.dirname(os.path.abspath(__file__))
- print(current_dir) # G:\PyCharm
- log_dir = os.path.join('../logs')
- # 日志名称构建
- log_file_name = datetime.now().strftime("%Y-%m-%d") + '.log'
- log_file_path = log_dir + '/' + log_file_name
- print(log_file_path) # ../logs/2022-03-09.log
- # 2.2 好的,将日志写进log文件中
- self.file_handle = logging.FileHandler(log_file_path, 'a', encoding='utf-8')
- formatter = logging.Formatter(
- '%(asctime)s %(filename)s %(funcName)s %(levelno)s: [%(levelname)s] ---> %(message)s')
- self.file_handle.setFormatter(formatter)
- self.logger.addHandler(self.file_handle)
-
- def get_log(self):
- return self.logger
-
- def close_handle(self):
- self.logger.removeHandler(self.file_handle)
- self.file_handle.close()
-
-
-
- rl = RecordLog()
- log_info = rl.get_log()
- acc = Test_accountMonitorWasteWater()
- log_info.debug(acc.login())
复制代码 这里的acc.login()出错了后台会报错,但是不会记录到日志中,求解
|
|