示例#1
0
 def json(self, body={}):
     if (DEBUG_LOG):
         debug_id = Utils.unique_id()
         log().debug(
             json.dumps({
                 'LOG_ID': debug_id,
                 'IP_ADDRESS': request.remote_addr,
                 'REQUEST_URL': request.url,
                 'REQUEST_METHOD': request.method,
                 'PARAMETERS': request.args,
                 'RESPONSES': body
             }))
     body['debug_id'] = debug_id
     return jsonify(body)
示例#2
0
def ExceptionApi(code, e):
    """ 接口异常处理 """
    exc_type, exc_value, exc_traceback = sys.exc_info()
    if DEBUG_LOG:
        if SAVE_LOG == 1:
            log().exception(e)
        elif SAVE_LOG == 2:
            LogService().add(e, 1, 3) #导致文件互相引用
    body = {}
    body['error_code'] = code
    body['error'] = True
    body['show'] = False
    body['debug_id'] = Utils.unique_id()
    dBSession.close()
    #这里exc_type 和exc_value信息重复,所以不打印
    body['traceback'] = traceback.format_exception([], exc_value, exc_traceback)
    return make_response(jsonify(body))
示例#3
0
 def json(self, body={}):
     if DEBUG_LOG:
         debug_id = Utils.unique_id()
         data = {
             'LOG_ID': debug_id,
             'IP_ADDRESS': request.remote_addr,
             'REQUEST_URL': request.url,
             'REQUEST_METHOD': request.method,
             'PARAMETERS': request.args,
             'RESPONSES': body
         }
         if SAVE_LOG == 1:
             log().debug(data)
         elif SAVE_LOG == 2:
             LogService().add(json.dumps(data), 1, 2)
     body['debug_id'] = debug_id
     return jsonify(body)
示例#4
0
def SocketExceptionApi(code, e):
    """ 接口异常处理 """
    exc_type, exc_value, exc_traceback = sys.exc_info()
    error_trace = traceback.format_exception(exc_type, exc_value, exc_traceback)
    if DEBUG_LOG:
        if SAVE_LOG == 1:
            log().exception(error_trace)
        elif SAVE_LOG == 2:
            LogService().add(json.dumps(error_trace), 1, 3) #导致文件互相引用
    body = {}
    body['error_code'] = code
    body['error'] = True
    body['show'] = False
    body['debug_id'] = Utils.unique_id()
    #这里exc_type 和exc_value信息重复,所以不打印
    body['traceback'] = error_trace
    dBSession.close()
    return body