> ## 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-CN/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` | MongoDB、Redis 和 git-bridge，它们运行在各自的 pod 中 |

### 读取日志

| 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-CN/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` 复制日志文件、对 Overleaf pod（启动和迁移）以及 `mongo-0` 执行 `kubectl logs`。


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