# Access logs

> View the last 3 days of access logs for buckets and CDN domains in the console, filter by status code, and troubleshoot with logs.

Access logs record every request that reaches a bucket or CDN domain. You can use them to troubleshoot 403s and 404s and find where traffic comes from. Logs don't need to be enabled and aren't charged separately.

Entry point: **Observability › Access logs (观测 › 访问日志)**, at <https://console.bitiful.com/observe/logs>.

## View logs

### Select a source

In the **Select bucket / domain (请选择 桶 / 域名)** drop-down, choose a bucket or a CDN domain. When you open the page, the first bucket is selected by default, or the first domain if you have no buckets. You can type in the drop-down to search.

### Filter by status code

In the **Status code (状态码)** drop-down, choose `2XX`, `3XX`, `4XX`, or `5XX`. You can select several. If you select none or include `ALL`, everything is shown.

### View more

Each load fetches 100 entries, from newest to oldest. Scroll to the bottom and click **Load more (加载更多)** to see earlier logs. The page doesn't refresh automatically. Click **Refresh (刷新)** to get the latest logs.

## Field descriptions

| Column                 | Description                                                                    |
| ---------------------- | ------------------------------------------------------------------------------ |
| **CODE**               | The HTTP status code. Green for 2XX, orange for 3XX, pink for 4XX, red for 5XX |
| **Method (方式)**        | The request method, such as GET, PUT, HEAD                                     |
| **Access time (访问时间)** | The request time, shown in your computer's time zone                           |
| **IP address (IP地址)**  | The visitor's IP. CDN logs also show a country or region flag                  |
| **Size (大小)**          | The bytes transferred by this request, converted in powers of 1000             |
| **Path (路径)**          | The full URL. Bucket logs include query parameters                             |

Hovering over **Path** shows more information:

| Field          | Description                                              |
| -------------- | -------------------------------------------------------- |
| **Request ID** | Only CDN logs have it                                    |
| **User Agent** | The client identifier                                    |
| **Referer**    | The referring page. Shows "空" (empty) when there is none |

## Limits

- You can view only the last 3 days of logs. For a longer period, use the [log API](https://docs.bitiful.com/en/developer/api/s4.md) to pull logs on a schedule and store them yourself.
- The console has no export feature and can't search by path, IP, or Referer. When you need that, pull with the API and analyze.
- CDN requests that hit the cache appear only in CDN logs, not in bucket logs. Every CDN request you can see in bucket logs is an origin fetch.

## Pull logs with the API

```bash
curl -G "https://api.bitiful.com/s4/data/<bucket-name>/logs" \
  -H "Authorization: <API Token>" \
  --data-urlencode "start_time=$(date +%s)000000000" \
  --data-urlencode "codes=4XX,5XX" \
  --data-urlencode "limit=1000"
```

`start_time` is the upper bound of the query, and logs earlier than it are returned. For parameters, response fields, and pagination, see the [Object storage API](https://docs.bitiful.com/en/developer/api/s4.md) and the [Static CDN API](https://docs.bitiful.com/en/developer/api/cdn.md).

## Troubleshoot with logs

| Symptom                | What to look at first                                                                                                                                                                                                                                                                                                                                                                                                               |
| ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Lots of 403s           | Check whether **Path** has signature parameters. Requests without a signature are anonymous access, so check [public read](https://docs.bitiful.com/en/bitiful-s4/handbook/public-read.md) and [access control](https://docs.bitiful.com/en/bitiful-s4/handbook/anti-leech.md). For signed ones, check whether the signature has expired. See [Error codes and troubleshooting](https://docs.bitiful.com/en/developer/s3/errors.md) |
| Traffic suddenly rises | Look at **Size** and **Referer** to find the hotlinked files and the referring sites, then set up [hotlink protection](https://docs.bitiful.com/en/bitiful-s4/handbook/anti-leech.md)                                                                                                                                                                                                                                               |
| Lots of 404s           | Check whether **Path** has extra or missing directories, and whether the case matches                                                                                                                                                                                                                                                                                                                                               |
| 5XX                    | Note the time, the path, and the `x-amz-request-id` in the response headers, and contact support                                                                                                                                                                                                                                                                                                                                    |

## FAQ

<details>
<summary>Why can't I see a request I just made?</summary>

Logs are near real time, so there's usually a short delay. Wait a moment and click **Refresh**.

</details>

<details>
<summary>Why isn't my CDN domain in the drop-down?</summary>

Only CDN domains under your current account are shown. For a domain you just created that hasn't had any requests, the list is empty after you select it.

</details>

<details>
<summary>Why don't the request counts in the logs match my bill?</summary>

Logs are for troubleshooting. Billing follows [Charges](https://docs.bitiful.com/en/prices/handbook/bills.md).

</details>
