跳转至

查询日志

1. 接口描述

接口请求路径:POST /prod-api/cdn/layer7/log/v2/describeLogs

describeLogs(V2)用于查询七层访问日志趋势与日志明细。一次请求可在 action 中同时请求趋势(logTread)与列表(logs),返回的 dataaction 顺序一一对应。

仅支持查询最近 360 天内的数据,单次查询时间跨度不超过 40 天。Token 获取方式见 密钥鉴权

2. 输入参数

以下请求参数列表仅列出了接口请求参数和部分公共参数,完整公共参数列表见 公共请求参数

参数名称 必选 类型 描述
action Array 操作列表,不能为空
action.metricName String 操作类型,支持以下值:
logTread:日志趋势图
logs:日志列表
示例值:logs
action.pageNo Integer 页码,从 1 开始。仅 logs 有效,默认 1
示例值:1
action.pageSize Integer 每页条数。仅 logs 有效,默认 10
示例值:15
otherFilter Array 筛选条件列表
otherFilter.oneVal String 筛字段,支持以下值:
request_id:请求 ID
domain:域名
ip:IP
server_port:来源端口
http_user_agent:客户端
referer:来源地址
country_name:国家/地区
status:状态码
url:请求资源路径
cache:缓存
示例值:domain
otherFilter.twoVal String 操作符,支持以下值:
eq:等于
ne:不等于
contain:包含
示例值:eq
otherFilter.threeVal Array of String 筛选值
示例值:["demo.com"]
searchHeader Object 额外搜索头信息,可传空对象 {}
params.beginTime String 开始时间,格式 yyyy-MM-dd HH:mm:ss,仅支持查询最近 360 天
示例值:2026-05-10 17:58:49
params.endTime String 结束时间,格式 yyyy-MM-dd HH:mm:ss,单次跨度不超过 40 天
示例值:2026-05-13 17:58:49

3. 示例

示例1 查询日志趋势与列表

输入示例

{
  "action": [
    {
      "metricName": "logTread"
    },
    {
      "metricName": "logs",
      "pageNo": 1,
      "pageSize": 15
    }
  ],
  "otherFilter": [],
  "searchHeader": {},
  "params": {
    "beginTime": "2026-05-10 17:58:49",
    "endTime": "2026-05-13 17:58:49"
  }
}

代码调用

请将 {登录域名}token 替换为实际值。

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

public class DescribeLogsV2Test {

    public static void main(String[] args) throws Exception {
        String url = "https://{登录域名}/prod-api/cdn/layer7/log/v2/describeLogs";
        String token = "eyJhbGciOiJIUzUxMiJ9.xxxxxx";

        String requestBody = "{"
                + "\"action\":["
                + "{\"metricName\":\"logTread\"},"
                + "{\"metricName\":\"logs\",\"pageNo\":1,\"pageSize\":15}"
                + "],"
                + "\"otherFilter\":[],"
                + "\"searchHeader\":{},"
                + "\"params\":{"
                + "\"beginTime\":\"2026-05-10 17:58:49\","
                + "\"endTime\":\"2026-05-13 17:58:49\""
                + "}"
                + "}";

        try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
            HttpPost httpPost = new HttpPost(url);
            httpPost.setHeader("Authorization", "Bearer " + token);
            httpPost.setEntity(new StringEntity(requestBody, ContentType.APPLICATION_JSON));

            try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
                int statusCode = response.getStatusLine().getStatusCode();
                String body = EntityUtils.toString(response.getEntity(), "UTF-8");
                System.out.println("Status Code: " + statusCode);
                System.out.println("Body: " + body);
            }
        }
    }
}
package main

import (
    "bytes"
    "fmt"
    "io"
    "net/http"
)

func main() {
    url := "https://{登录域名}/prod-api/cdn/layer7/log/v2/describeLogs"
    token := "eyJhbGciOiJIUzUxMiJ9.xxxxxx"

    requestBody := []byte(`{
  "action": [
    {"metricName": "logTread"},
    {"metricName": "logs", "pageNo": 1, "pageSize": 15}
  ],
  "otherFilter": [],
  "searchHeader": {},
  "params": {
    "beginTime": "2026-05-10 17:58:49",
    "endTime": "2026-05-13 17:58:49"
  }
}`)

    req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(requestBody))
    if err != nil {
        panic(err)
    }
    req.Header.Set("Authorization", "Bearer "+token)
    req.Header.Set("Content-Type", "application/json")

    resp, err := http.DefaultClient.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    body, err := io.ReadAll(resp.Body)
    if err != nil {
        panic(err)
    }
    fmt.Println("Status Code:", resp.StatusCode)
    fmt.Println("Body:", string(body))
}

输出示例

{
  "msg": "成功",
  "code": 200,
  "data": [
    {
      "metricName": "logTread",
      "objectArrayList": [
        [1778493600000, 1],
        [1778497200000, 1],
        [1778526000000, 2]
      ],
      "count": 5
    },
    {
      "metricName": "logs",
      "list": [
        {
          "scheme": "https",
          "requestMethod": "GET",
          "ua": {
            "os": "Windows",
            "name": "Chrome",
            "os_name": "Windows",
            "device": "Other",
            "major": "147",
            "minor": "0",
            "patch": "0",
            "build": ""
          },
          "geoip": {
            "timezone": "Asia/Shanghai",
            "ip": "113.116.195.49",
            "city_name": "Shenzhen",
            "country_name": "China",
            "country_code2": "CN",
            "region_name": "Guangdong",
            "latitude": 22.5333,
            "longitude": 114.1333
          },
          "httpUserAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36",
          "protocol": "HTTP/1.1",
          "contentType": "",
          "responsetime": "0.016",
          "cache": "",
          "ip": "113.116.195.49",
          "url": "/",
          "size": 3631,
          "domain": "waf2.example.com",
          "serverPort": "443",
          "requestId": "c8f204a0a780cd709ddee9eaba681a7c",
          "referer": "",
          "status": 200,
          "timestamp": "2026-05-12 11:38:04"
        }
      ]
    }
  ]
}

4. 输出参数

参数名称 类型 描述
code Integer 状态码。示例值:200
msg String 提示信息。示例值:成功
data Array 结果列表,顺序与请求 action 一致
data[].metricName String 指标名称:logTreadlogs
data[].objectArrayList Array 日志趋势(logTread)。每个点为 [毫秒时间戳, 数量]
data[].count Integer 趋势汇总数量(logTread
data[].list [LogItem] 日志明细列表(logs

5. 错误码

HTTP 状态码 / 业务提示 描述
200 成功
401 未鉴权或 Token 无效
403 无权限
请选择时间范围 未传 params 或缺少 beginTime / endTime
只能查询最近360天的数据 开始时间超出限制
一次只能查询40天的数据 时间跨度超过 40 天
请选择操作类型 未传 action

6. 数据模型

LogItem

单条访问日志。

参数名称 类型 描述
scheme String 协议场景,如 httphttps
requestMethod String 请求方法。示例值:GET
ua Object UA 解析信息,含 nameosos_namedevicemajor
geoip Object 地理位置,含 ipcity_namecountry_nametimezonelatitudelongitude
httpUserAgent String 原始 User-Agent
protocol String 协议版本。示例值:HTTP/1.1
contentType String 内容类型
responsetime String 响应时长(秒)
cache String 缓存状态
ip String 客户端 IP
url String 请求路径
size Integer 响应大小(字节)
domain String 访问域名
serverPort String 服务端口
requestId String 请求 ID
referer String Referer
status Integer HTTP 状态码
timestamp String 请求时间。示例值:2026-05-12 11:38:04