> ## Documentation Index
> Fetch the complete documentation index at: https://ayakaleaf-pro.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 日誌

> 讀取、複製並保存 Kubernetes 部署的日誌。

Ayakaleaf Pro Pod 內的每個服務都會在 `/var/log/overleaf/` 下寫入各自的日誌檔案；`kubectl logs` 只會顯示容器的啟動輸出（初始化指令碼、遷移）。Toolkit 的 `bin/logs` 讀取的是相同的檔案，請參閱[日誌](https://ayakaleaf-pro.mintlify.site/zh-TW/on-premises/configuration/overleaf-toolkit/logging.md)。

| 位置 | 內容 |
| - | - |
| `kubectl -n overleaf logs <pod>` | 啟動：密鑰檢查、遷移（`Finished migrations`）、服務啟動 |
| Pod 中的 `/var/log/overleaf/<service>.log` | `web.log`、`web-api.log`、`clsi.log`、`real-time.log`、`document-updater.log`、`docstore.log`、`filestore.log`、`history-v1.log`、`project-history.log`、`chat.log`、`notifications.log`、`linked-url-proxy.log`，以及啟用 Dropbox 時的 `third-party-datastore.log` |
| Pod 中的 `/var/log/nginx/` | 位於各服務前方之 nginx 的 `access.log`、`error.log` |
| `kubectl -n overleaf logs mongo-0`、`redis-0`、`git-bridge-0` | 在各自 Pod 中執行的 MongoDB、Redis 與 git-bridge |

### 讀取日誌

| Toolkit | Kubernetes |
| - | - |
| `bin/logs web` | `kubectl -n overleaf exec deploy/overleaf -- tail -n 20 /var/log/overleaf/web.log` |
| `bin/logs -f web clsi` | `kubectl -n overleaf exec deploy/overleaf -- tail -f /var/log/overleaf/web.log /var/log/overleaf/clsi.log` |
| `bin/logs -n all web > web.log` | `kubectl -n overleaf cp overleaf/<pod>:/var/log/overleaf/web.log web.log` |
| `bin/logs mongo` | `kubectl -n overleaf logs mongo-0` |

在[多個副本](https://ayakaleaf-pro.mintlify.site/zh-TW/on-premises/configuration/kubernetes/horizontal-scaling.md)的情況下，每個 Pod 都有自己的檔案：請使用 Pod 名稱（`overleaf-0`、`overleaf-1`……）取代 `deploy/overleaf`。HAProxy 加入的 `X-Served-By` 標頭可指出是哪個副本回應了請求。

ConfigMap 中的 `LOG_LEVEL`（預設為 `info`，另有 `debug`、`warn`、`error`）會一次設定 Pod 中所有服務的層級。

### 保存日誌

這些檔案位於容器中，當 Pod 被取代時就會遺失。若要保存，請在 Deployment 或 StatefulSet 中於 `/var/log/overleaf` 掛載磁碟區，例如節點上的 `hostPath` 或 PersistentVolumeClaim：

```yaml theme={null}
          volumeMounts:
            # ...
            - name: logs
              mountPath: /var/log/overleaf
      volumes:
        # ...
        - name: logs
          hostPath:
            path: /srv/overleaf-logs
            type: DirectoryOrCreate
```

容器每天會輪替檔案並保留五份，因此磁碟區不會無限制地成長。您也可以使用叢集的日誌代理程式從該路徑收集日誌。

### 在 Kubernetes 上的測試

在 Kubernetes 1.37 上以三個副本並如上所述於 `/var/log/overleaf` 掛載 `hostPath` 磁碟區，每個節點的 `/srv/overleaf-logs` 都保存了其副本的十二個服務日誌，而表格中的指令也如所示正常運作：透過 `kubectl exec` 執行 `tail`、以 `kubectl cp` 複製日誌檔案、以 `kubectl logs` 查看 Overleaf Pod（啟動與遷移）以及 `mongo-0` 的日誌。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.