Ejemplo n.º 1
0
    def dispatch_request(self):
        start_time = time.time()
        resp = super(My_Flask, self).dispatch_request()
        cost = time.time() - start_time
        req = _request_ctx_stack.top.request
        ret_data = {}
        try:
            if resp:
                resp_data = resp.data
                if resp.data.startswith("jQuery") or resp.data.startswith(
                        'jsonp'):
                    first = resp_data.find('(')
                    resp_data = resp_data[first + 1:-2]
                ret_data = json_helper.loads(resp_data)
        except:
            errinfo = traceback.format_exc()
            errinfo = 'resp:%s exc:%s' % (resp, errinfo)
            log_helper.log_error(errinfo)
        ret_code = ret_data.get('code')
        if ret_code is not None:
            ret_code = int(ret_code)

        #log 不要打印password
        get_args = dict(req.args.items())
        get_args.pop('password', None)
        post_args = dict(req.form.items())
        post_args.pop('password', None)

        logging.debug("ip:%s path:%s cost:%.3fs  get args:%s post args:%s ret:%s ret_msg:%s",\
                      ip_helper.get_real_ip(req),req.full_path, cost, get_args.items(), post_args.items(), \
                      ret_code, const_define.ErrorMsg.MSG_DICT.get(ret_code))
        return resp
Ejemplo n.º 2
0
    def dispatch_request(self):
        start_time = time.time()
        resp = super(My_Flask,self).dispatch_request()
        cost = time.time() - start_time
        req = _request_ctx_stack.top.request
        ret_data = {}
        try:
            if resp:
                resp_data = resp.data
                if resp.data.startswith("jQuery") or resp.data.startswith('jsonp'):
                    first = resp_data.find('(')
                    resp_data = resp_data[first+1:-2]
                ret_data = json_helper.loads(resp_data)
        except:
            errinfo = traceback.format_exc()
            errinfo = 'resp:%s exc:%s'%(resp,errinfo)
            log_helper.log_error( errinfo )
        ret_code = ret_data.get('code')
        if ret_code is not None:
            ret_code = int(ret_code)

        #log 不要打印password
        get_args = dict(req.args.items())
        get_args.pop('password',None)
        post_args = dict(req.form.items())
        post_args.pop('password',None)

        logging.debug("ip:%s path:%s cost:%.3fs  get args:%s post args:%s ret:%s ret_msg:%s",\
                      ip_helper.get_real_ip(req),req.full_path, cost, get_args.items(), post_args.items(), \
                      ret_code, const_define.ErrorMsg.MSG_DICT.get(ret_code))
        return resp
Ejemplo n.º 3
0
def global_error_handler( exception ):
    from flask import request
    errinfo = traceback.format_exc()
    errinfo = 'path:%s args:%s %s'%(request.full_path,request.values,errinfo)
    log_helper.log_error( errinfo , True)
    resp = {
        'code' : ErrorCode.SYS_ERR,
    }
    return json_helper.write(resp)
Ejemplo n.º 4
0
def global_error_handler(exception):
    from flask import request
    errinfo = traceback.format_exc()
    errinfo = 'path:%s args:%s %s' % (request.full_path, request.values,
                                      errinfo)
    log_helper.log_error(errinfo, True)
    resp = {
        'code': ErrorCode.SYS_ERR,
    }
    return json_helper.write(resp)
Ejemplo n.º 5
0
def is_valid_app_uuid(app_uuid):
    try:
        if not app_uuid:
            return False
        tmp_list = app_uuid.split("-")
        if len(tmp_list) != 5:
            logging.error(" len [%s] %s",len(tmp_list),tmp_list)
            return False
        if len(tmp_list[0]) != 8 and len(tmp_list[1]) != 4 and len(tmp_list[2]) != 4 and len(tmp_list[3]) != 4 and len(tmp_list[4]) != 12:
            logging.error("len is error %s",tmp_list)
            return False
        return True
    except:
        log_helper.log_error(traceback.format_exc(), True)
        return False
Ejemplo n.º 6
0
def is_valid_app_uuid(app_uuid):
    try:
        if not app_uuid:
            return False
        tmp_list = app_uuid.split("-")
        if len(tmp_list) != 5:
            logging.error(" len [%s] %s",len(tmp_list),tmp_list)
            return False
        if len(tmp_list[0]) != 8 and len(tmp_list[1]) != 4 and len(tmp_list[2]) != 4 and len(tmp_list[3]) != 4 and len(tmp_list[4]) != 12:
            logging.error("len is error %s",tmp_list)
            return False
        return True
    except:
        log_helper.log_error(traceback.format_exc(), True)
        return False