# Logging

If an error occurs in any of the processes it will be written to the respective log file such as `/var/log/overleaf/web.log`.

Toolkit users can have a look at the logs inside the container using the `bin/logs` script:

```bash
# You can use the following command to view the web service logs
bin/logs web

# You can use --help for help
bin/logs --help

# You can also look at the logs for multiple services at once:
bin/logs filestore docstore web clsi

# You can follow the log output using the -f flag
bin/logs -f filestore docstore web clsi

# You can use the -n {number} flag to limit the number of lines to print (default 50)
bin/logs -n 50 web

# You can use the -n all flag to show all log lines
bin/logs -n all web

# You can use > to redirect the output to a file
bin/logs -n all web > web.log
```

You can use the `bin/logs` script to view logs for the following services: `clsi`, `contacts`, `docstore`, `document-updater`, `filestore`, `git-bridge`, `mongo`, `notifications`, `real-time`, `redis`, `spelling`, `tags`, `track-changes`, `web`, `web-api`, `history-v1`, `project-history`.

## Copying logs

You can copy log files from the main `sharelatex` container to local computer using the following command:

```bash
docker cp sharelatex:/var/log/overleaf/{service-name}.log {service-name}.log
```

## Persisting logs

Docker containers are ephemeral which means that any files/directories created within the container during runtime will be discarded if the container is ever recreated (for example, when running the `bin/up` command). This **includes** log files.&#x20;

If you'd like to retain access to important log files between container recreation, you can set the environment variable `OVERLEAF_LOG_PATH` in the `config/overleaf.rc` file with the Toolkit. This variable should be set to the directory on the host that will be mounted to the log directory inside the `sharelatex` container. Once you've made this configuration change and run the `bin/up -d` command, log files will be persisted and you'll be able to access the logs directly from the Docker host.

{% hint style="danger" %}
You'll need to set the owner of the logs directory used in the bind-mount to the `www-data` user (uid=33) with the permissions `drwxr-xr-x` (755).&#x20;

As an example, you can can set the owner using `chown 33:33 data/overleaf/logs` and the permissions using `chmod 755 data/overleaf/logs`.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.overleaf.com/on-premises/configuration/overleaf-toolkit/logging.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
