有奖捉虫:云通信与企业服务文档专题,速来> HOT

接口描述

功能描述

GetFunctionLogs 根据设置的日志查询条件返回函数日志。

接口域名

接口请求域名为:scf.api.qcloud.com

请求

语法示例:

GET https://scf.api.qcloud.com/v2/index.php?Action=GetFunctionLogs
    &<公共请求参数>
    &offset=<OffsetValue>
    &limit=<Limit>
    &orderby=<sort type>
    &functionName=<FunctionName>

请求参数

以下请求参数为本接口接口请求参数,正式调用时需要加上公共请求参数,详见 公共请求参数 页面。其中,此接口的 Action 字段为 GetFunctionLogs。

参数名称 描述 类型 必选
functionName 函数名称 String
offset 数据偏移量,默认值为 0 Int
limit 返回数据长度,默认值为 20 Int
order 以升序还是降序的方式对日志进行排序,可选值 desc和 acs String
orderby 根据某个字段排序日志,支持以下字段:startTime、functionName、requestId、duration和 memUsage String
filter 日志过滤条件。可用来区分正确和错误日志,filter.retCode=not0 表示只返回错误日志,filter.retCode=is0 表示只返回正确日志,不传,则返回所有日志。 Object

响应

响应示例:

{
    "code": 0,
    "message": "",
    "codeDesc": "Success",
    "total": 2,
    "data": [
        {
            "functionName": "testnode",
            "retMsg": "\"ok\"",
            "requestId": "b5a9c642-9c51-11e7-a46e-5254001df6c6",
            "startTime": "2017-09-18 17:14:01",
            "retCode": 0,
            "invokeFinished": 1,
            "duration": 2.735,
            "billDuration": 100,
            "memUsage": 131072,
            "log": "2017-09-18T09:14:01.236Z\tundefined\tHello World\n2017-09-18T09:14:01.236Z\tundefined\t{ Records: [ { CMQ: [Object] } ] }\n2017-09-18T09:14:01.237Z\tundefined\t{ msgBody: '4',\n  msgId: '3096224743817224',\n  msgTag: '',\n  publishTime: '2017-09-18T17:14:01Z',\n  requestId: '5761047512720426890',\n  subscriptionName: 'alfred-test',\n  topicName: 'alfred-test',\n  topicOwner: 1251762227,\n  type: 'topic' }\n2017-09-18T09:14:01.237Z\tundefined\t{ callbackWaitsForEmptyEventLoop: [Getter/Setter],\n  done: [Function: done],\n  succeed: [Function: succeed],\n  fail: [Function: fail],\n  memory_limit_in_mb: 128,\n  time_limit_in_ms: 30000 }\n"
        },
        {
            "functionName": "testnode",
            "retMsg": "\"ok\"",
            "requestId": "b33b9d0b-9c51-11e7-b38f-525400c7c826",
            "startTime": "2017-09-18 17:13:57",
            "retCode": 0,
            "invokeFinished": 1,
            "duration": 7.437,
            "billDuration": 100,
            "memUsage": 131072,
            "log": "2017-09-18T09:13:57.155Z\tundefined\tHello World\n2017-09-18T09:13:57.156Z\tundefined\t{ Records: [ { CMQ: [Object] } ] }\n2017-09-18T09:13:57.158Z\tundefined\t{ msgBody: '3',\n  msgId: '3096224743817223',\n  msgTag: '',\n  publishTime: '2017-09-18T17:13:57Z',\n  requestId: '5761047512720426853',\n  subscriptionName: 'alfred-test',\n  topicName: 'alfred-test',\n  topicOwner: 1251762227,\n  type: 'topic' }\n2017-09-18T09:13:57.159Z\tundefined\t{ callbackWaitsForEmptyEventLoop: [Getter/Setter],\n  done: [Function: done],\n  succeed: [Function: succeed],\n  fail: [Function: fail],\n  memory_limit_in_mb: 128,\n  time_limit_in_ms: 30000 }\n"
        }
    ]
}

响应参数

参数名称 描述 类型
code 公共错误码, 0 表示成功,其他值表示失败 Int
message 模块错误信息描述,与接口相关 String
codeDesc 英文错误码,成功返回 Success,失败有相应的英文说明 String
total 日志总量 Int
data 返回日志信息列表 Object

返回的每条日志数据包含如下数据结构:

参数名称 描述 类型
function_name 该日志对应的函数名称 String
retMsg 函数执行完成后的返回值 String
requestId 执行该函数对应的requestId String
startTime 函数开始执行时的时间点 String
ret_code 函数执行结果,如果是 0 表示执行成功,其他值表示失败 Int
invokeFinished 函数调用是否结束,如果是 1 表示执行结束,其他值表示调用异常 Int
duration 函数执行耗时,单位为 ms Float
billDuration 函数计费时间,根据 duration 向上取最近的 100ms,单位为ms Int
memUsage 函数执行时消耗实际内存大小,单位为 Byte Int
log 函数执行过程中的日志输出 String

实际案例

请求

GET https://scf.api.qcloud.com/v2/index.php?
    Action=GetFunctionLogs
    &SecretId=AKIDutrojKl3CKQZNAr763UXks05898Lmciu
    &Nonce=47400
    &Timestamp=1505726068
    &Region=gz
    &Signature=gcFINOIX37qkwL%2FIkiRY9hQDSkM%3D
    &functionName=testnode
    &limit=2

响应

{
    "code": 0,
    "message": "",
    "codeDesc": "Success",
    "total": 2,
    "data": [
        {
            "functionName": "testnode",
            "retMsg": "\"ok\"",
            "requestId": "b5a9c642-9c51-11e7-a46e-5254001df6c6",
            "startTime": "2017-09-18 17:14:01",
            "retCode": 0,
            "invokeFinished": 1,
            "duration": 2.735,
            "billDuration": 100,
            "memUsage": 131072,
            "log": "2017-09-18T09:14:01.236Z\tundefined\tHello World\n2017-09-18T09:14:01.236Z\tundefined\t{ Records: [ { CMQ: [Object] } ] }\n2017-09-18T09:14:01.237Z\tundefined\t{ msgBody: '4',\n  msgId: '3096224743817224',\n  msgTag: '',\n  publishTime: '2017-09-18T17:14:01Z',\n  requestId: '5761047512720426890',\n  subscriptionName: 'alfred-test',\n  topicName: 'alfred-test',\n  topicOwner: 1251762227,\n  type: 'topic' }\n2017-09-18T09:14:01.237Z\tundefined\t{ callbackWaitsForEmptyEventLoop: [Getter/Setter],\n  done: [Function: done],\n  succeed: [Function: succeed],\n  fail: [Function: fail],\n  memory_limit_in_mb: 128,\n  time_limit_in_ms: 30000 }\n"
        },
        {
            "functionName": "testnode",
            "retMsg": "\"ok\"",
            "requestId": "b33b9d0b-9c51-11e7-b38f-525400c7c826",
            "startTime": "2017-09-18 17:13:57",
            "retCode": 0,
            "invokeFinished": 1,
            "duration": 7.437,
            "billDuration": 100,
            "memUsage": 131072,
            "log": "2017-09-18T09:13:57.155Z\tundefined\tHello World\n2017-09-18T09:13:57.156Z\tundefined\t{ Records: [ { CMQ: [Object] } ] }\n2017-09-18T09:13:57.158Z\tundefined\t{ msgBody: '3',\n  msgId: '3096224743817223',\n  msgTag: '',\n  publishTime: '2017-09-18T17:13:57Z',\n  requestId: '5761047512720426853',\n  subscriptionName: 'alfred-test',\n  topicName: 'alfred-test',\n  topicOwner: 1251762227,\n  type: 'topic' }\n2017-09-18T09:13:57.159Z\tundefined\t{ callbackWaitsForEmptyEventLoop: [Getter/Setter],\n  done: [Function: done],\n  succeed: [Function: succeed],\n  fail: [Function: fail],\n  memory_limit_in_mb: 128,\n  time_limit_in_ms: 30000 }\n"
        }
    ]
}