def request(self, flow: http.HTTPFlow): method, url = flow.request.method, flow.request.url mock_data = db.session.query(MockData).filter_by(method=method, status=1).all() match_data = self.get_matched_data(flow, mock_data) if match_data: logger.info('%s%6s %s', '▶', method, flow.request.path) content = json.dumps( self.mock(match_data.response), ensure_ascii=False) if match_data.response else '' content_type = { "Content-Type": match_data.content_type } if match_data.content_type else {} headers = self.mock( match_data.headers) if match_data.headers else {} logger.debug('Mock data: %s', content) flow.response = http.HTTPResponse.make( match_data.code, # (optional) status code content, # (optional) content { 'Access-Control-Allow-Origin': '*', **content_type, **headers }) else: logger.info( '%-2s%6s %s', '•', method, flow.request.path[:200] + (flow.request.path[200:] and '...'))
def docker_runner(): while True: try: change_ip() except KeyboardInterrupt: logger.info('keyboard interrupt') sys.exit(0) except Exception as e: print(e) pass
def running(): logger.info('FlowInterceptor is running, proxy server listening at http://{}'.format( human.format_address(ctx.master.server.address) ))
def __init__(self): self.mock = Mock().mock_js logger.info('FlowInterceptor init...')
# -*- coding:utf-8 -*- # __auth__ = mocobk # email: [email protected] from ilogger import logger # 默认级别为 INFO logger.debug('this is debug message') logger.info('this is info message') # 设置 logger 级别 logger.setLevel(logger.DEBUG) logger.debug('this is debug message') logger.info('this is info message') logger.warning('this is warning message') logger.warn('this is warning message') logger.error('this is error message') logger.critical('this is critical message') # 设置 logger 格式 logger.setFormatter( fmt='[%(asctime)s]%(levelname)7s[%(filename)s:%(lineno)s]: %(message)s') logger.debug('this is debug message') logger.info('this is info message')