日志模块配置:
import logging
import os
# 创建一个日志记录器
logger = logging.getLogger('my_logger')
logger.setLevel(logging.DEBUG)
# 创建一个文件处理器
log_file = 'my_log.log'
file_handler = logging.FileHandler(os.path.join(os.path.dirname(__file__), log_file), mode="w", encoding='utf-8')
file_handler.setLevel(logging.DEBUG)
# 创建一个控制台处理器
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.DEBUG)
# 创建一个格式化器
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
file_handler.setFormatter(formatter)
console_handler.setFormatter(formatter)
# 将处理器添加到记录器
logger.addHandler(file_handler)
logger.addHandler(console_handler)
流程中,使用对应的 logger
from decorator import calculate_time
from logging_config import logger
输出必要的日志:
logger.info(f"cookie的数据为:{cookie}")
控制台效果
日志文件效果
2024-06-03 00:27:51,952 - my_logger - INFO - 获取的异常详情页的result为:Terminated
2024-06-03 00:27:52,953 - my_logger - INFO - 轮询结果进行中。。。。。。
2024-06-03 00:27:52,953 - my_logger - INFO - 仍存在异常数据,获取的异常详情页的except_value_result为:[[{'values': ['0323vi4c7a403', '2', '19500', '2024-06-02T22:50:28+08:00[Asia/Shanghai]', '0323vi4c7a403', '1', '19500', '2024-06-02T21:41:57.914+08:00[Asia/Shanghai]']}, {'values': ['0323vi5d7b703', '2', '2000000', '2024-06-02T22:50:28+08:00[Asia/Shanghai]', '0323vi5d7b703', '1', '2000000', '2024-06-02T21:43:24.002+08:00[Asia/Shanghai]']}], [{'values': ['0323ve7h7a401', '2', '200000', '2024-06-02T21:24:34+08:00[Asia/Shanghai]', '0323ve7h7a401', '1', '200000', '2024-06-02T20:18:19.049+08:00[Asia/Shanghai]']}, {'values': ['0323vem27b605', '2', '600000', '2024-06-02T21:34:38+08:00[Asia/Shanghai]', '0323vem27b605', '1', '600000', '2024-06-02T20:26:31.098+08:00[Asia/Shanghai]']}], [{'values': ['0323v8st7a402', '2', '20000', '2024-06-02T19:29:01+08:00[Asia/Shanghai]', '0323v8st7a402', '15', '20000', '2024-06-02T18:20:33+08:00[Asia/Shanghai]']}, {'values': ['0323v8x07ba05', '2', '10000000', '2024-06-02T19:29:01+08:00[Asia/Shanghai]', '0323v8x07ba05', '15', '10000000', '2024-06-02T18:23:04+08:00[Asia/Shanghai]']}], [{'values': ['0323v7797be01', '2', '50000', '2024-06-02T18:52:01+08:00[Asia/Shanghai]', '0323v7797be01', '15', '50000', '2024-06-02T17:46:01+08:00[Asia/Shanghai]']}], [{'values': ['0323v0wr7bb05', '2', '5000000', '2024-06-02T16:39:01+08:00[Asia/Shanghai]', '0323v0wr7bb05', '1', '5000000', '2024-06-02T15:30:42.055+08:00[Asia/Shanghai]']}, {'values': ['0323v13e7bf05', '2', '1450000', '2024-06-02T16:39:01+08:00[Asia/Shanghai]', '0323v13e7bf05', '1', '1450000', '2024-06-02T15:34:21.404+08:00[Asia/Shanghai]']}], [{'values': ['0323u7pj7b402', '2', '5000000', '2024-06-02T06:04+08:00[Asia/Shanghai]', '0323u7pj7b402', '15', '5000000', '2024-06-02T04:59:25+08:00[Asia/Shanghai]']}, {'values': ['0323u8d27bb04', '2', '1000000', '2024-06-02T06:19:01+08:00[Asia/Shanghai]', '0323u8d27bb04', '1', '1000000', '2024-06-02T05:13:37.379+08:00[Asia/Shanghai]']}], [{'values': ['0323tx1h7b404', '2', '5000000', '2024-06-02T02:14:15+08:00[Asia/Shanghai]', '0323tx1h7b404', '1', '5000000', '2024-06-02T01:09:12.861+08:00[Asia/Shanghai]']}, {'values': ['0323txn47b403', '2', '200000', '2024-06-02T02:24:14+08:00[Asia/Shanghai]', '0323txn47b403', '15', '200000', '2024-06-02T01:21:56+08:00[Asia/Shanghai]']}, {'values': ['0323txqb7b700', '2', '110000', '2024-06-02T02:29:01+08:00[Asia/Shanghai]', '0323txqb7b700', '1', '110000', '2024-06-02T01:24:09.251+08:00[Asia/Shanghai]']}, {'values': ['0323txus7b804', '2', '1000000', '2024-06-02T02:34:01+08:00[Asia/Shanghai]', '0323txus7b804', '1', '1000000', '2024-06-02T01:26:36.523+08:00[Asia/Shanghai]']}, {'values': ['0323tyb57bb02', '2', '13000000', '2024-06-02T02:45:50+08:00[Asia/Shanghai]', '0323tyb57bb02', '1', '13000000', '2024-06-02T01:36:24.180+08:00[Asia/Shanghai]']}], [{'values': ['0323tqvs7b203', '2', '13700000', '2024-06-02T00:06:38+08:00[Asia/Shanghai]', '0323tqvs7b203', '1', '13700000', '2024-06-01T22:56:04.052+08:00[Asia/Shanghai]']}, {'values': ['0323tryn7ba06', '2', '350000', '2024-06-02T00:23:10+08:00[Asia/Shanghai]', '0323tryn7ba06', '1', '350000', '2024-06-01T23:19:21.259+08:00[Asia/Shanghai]']}, {'values': ['0323tsl87b001', '2', '2500000', '2024-06-02T00:39:29+08:00[Asia/Shanghai]', '0323tsl87b001', '15', '2500000', '2024-06-01T23:32:54+08:00[Asia/Shanghai]']}], [{'values': ['0323toa37b201', '2', '7785000', '2024-06-01T23:04:01+08:00[Asia/Shanghai]', '0323toa37b201', '15', '7785000', '2024-06-01T21:59:43+08:00[Asia/Shanghai]']}], [{'values': ['0323tm767a405', '2', '15000000', '2024-06-01T22:24:30+08:00[Asia/Shanghai]', '0323tm767a405', '1', '15000000', '2024-06-01T21:15:14.057+08:00[Asia/Shanghai]']}, {'values': ['0323tnmj7b900', '2', '1000000', '2024-06-01T22:58:36+08:00[Asia/Shanghai]', '0323tnmj7b900', '15', '1000000', '2024-06-01T21:45:37+08:00[Asia/Shanghai]']}], [{'values': ['0323tjbt7bc05', '2', '10000', '2024-06-01T21:19:06+08:00[Asia/Shanghai]', '0323tjbt7bc05', '1', '10000', '2024-06-01T20:12:45.802+08:00[Asia/Shanghai]']}], [{'values': ['0323tgtb7b803', '2', '15000000', '2024-06-01T20:24:01+08:00[Asia/Shanghai]', '0323tgtb7b803', '1', '15000000', '2024-06-01T19:18:48.041+08:00[Asia/Shanghai]']}, {'values': ['0323thg67bb08', '2', '2000000', '2024-06-01T20:41:40+08:00[Asia/Shanghai]', '0323thg67bb08', '1', '2000000', '2024-06-01T19:32:16.048+08:00[Asia/Shanghai]']}], [{'values': ['0323tdvv7bc02', '2', '1000000', '2024-06-01T19:24:36+08:00[Asia/Shanghai]', '0323tdvv7bc02', '1', '1000000', '2024-06-01T18:15:13.140+08:00[Asia/Shanghai]']}], [{'values': ['0323tby17b604', '2', '100000', '2024-06-01T18:44:01+08:00[Asia/Shanghai]', '0323tby17b604', '15', '100000', '2024-06-01T17:35:54+08:00[Asia/Shanghai]']}]]
2024-06-03 00:27:52,965 - my_logger - INFO - >>>>>>>>>>不可关闭的异常详情页,url为:https://console.sofa.antdigital.com/fsm/exception/detail/2220
2024-06-03 00:27:52,965 - my_logger - DEBUG - ================================最终不可关闭的异常详情url为:['https://console.sofa.antdigital.com/fsm/exception/detail/2220']
2024-06-03 00:27:52,965 - my_logger - DEBUG - ================================最终可闭的异常详情url为:[]
2024-06-03 00:27:55,048 - my_logger - DEBUG - ========统计运行时长:Function main_run took 582.7936472892761 seconds to run.
欢迎关注公众号,与Joker一起探索测试之道。