# 实时日志

`GET /s4/data/{bucket}/logs`

查询存储桶的实时访问日志，仅支持查询 **3 天内** 的日志。

结果按时间从新到旧排列，只返回早于 `start_time` 的日志。第一次请求把 `start_time` 设为当前时间；单次最多返回 1000 条，需要更多时，把返回结果中最后一条的 `access_time` 作为下一次请求的 `start_time` 继续翻页，直到返回空数组。

`access_time` 是纳秒整数，超出 JavaScript `Number` 的精确范围，翻页时请用 `BigInt` 或字符串处理。

Base URL: https://api.bitiful.com

Authentication: API key in header `Authorization`

## Path parameters

| Name | Type | Required | Description |
|---|---|---|---|
| `bucket` | string | yes | 存储桶名称。只能查询当前账户自己的桶。 |

## Query parameters

| Name | Type | Required | Description |
|---|---|---|---|
| `start_time` | integer | yes | 查询的时间上限，Unix 时间戳，单位 **纳秒**，只返回早于它的日志；同时用作分页游标。必须在最近 3 天内，缺失或更早会返回 403。例如用 `$(date +%s)000000000` 取当前时间。 |
| `codes` | string | no | 按 HTTP 状态码过滤，可选 `ALL`、`2XX`、`3XX`、`4XX`、`5XX`，必须大写。多个值用英文逗号分隔，例如 `4XX,5XX`。不传等于 `ALL`。 |
| `limit` | integer | no | 单次返回的条数。不传、小于 1 或大于 1000 时按 1000 处理。 |

## Example request

```bash
curl -X GET https://api.bitiful.com/s4/data/my-bucket/logs
```

## Responses

- **200**: 日志列表。没有匹配的日志时 `data` 是空数组。
- **401**: 缺少 API Token，或 Token 无效。
- **403**: 参数不合法、`start_time` 早于 3 天前或缺失、存储桶不属于当前账户，或账户被限制。
- **500**: 服务端错误，请稍后重试。

### Example response (200)

```json
{
  "data": [
    {
      "method": "GET",
      "code": 200,
      "access_time": 1795515998868996000,
      "remote_ip": "203.0.113.10",
      "size": 48213,
      "path": "https://my-bucket.s3.bitiful.net/images/cover.jpg?w=800&fmt=webp",
      "ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)",
      "referer": "https://www.example.com/"
    }
  ]
}
```
