# Logs
Logs are what your live app prints: requests, warnings and errors. Use them to find out why a live app misbehaves. They are off until you turn them on.
For why a deploy itself failed, use **See why** on the deploy (see [Deploy an app](/docs/deploy/deploy-an-app)). For an agent's runs, use **Log and files** on the run (see [Runs and approvals](/docs/agents/runs)).
## Before you start [#before-you-start]
They are off by default. Your spend shows in (see [Credits](/docs/workspace/credits)).
- A deployed project.
- To turn logs on or off, you need to be able to change the project.
## Turn logs on [#turn-logs-on]
### Open the project's settings [#open-the-projects-settings]
Open the project from , go to **Settings** (see [Project settings](/docs/projects/settings)) and choose the **Deploy** section ("How your app runs once it is live, where it deploys from, and what it prints").
### Turn on Keep logs [#turn-on-keep-logs]
Under **Logs**, turn on **Keep logs**. It takes effect within a minute, no new deploy needed.
### Choose how long to keep them [#choose-how-long-to-keep-them]
Under **Keep for**, choose 1, 3, 5, 7, 14 or 30 days. Older lines are removed on their own.
```python
from klarety import Nexus
nx = Nexus.connect()
print(nx.projects.logs("PROJECT_ID"))
nx.projects.set_logs("PROJECT_ID", enabled=True, days=7)
```
`days` is one of 1, 3, 5, 7, 14 or 30. `set_logs(..., enabled=False)` turns them off.
## Read the last hour [#read-the-last-hour]
**Last hour** shows the newest lines your app printed; select **Refresh** for more. When nothing was printed, it says "Nothing printed in the last hour."
```python
for line in nx.projects.log_lines("PROJECT_ID", minutes=60):
print(line)
api_lines = nx.projects.log_lines("PROJECT_ID", minutes=15, service="api")
```
Lines come newest last. Pass `service` to read one part of the app. The answer is empty while logs are off.
## What you see when it worked [#what-you-see-when-it-worked]
Within a minute, new lines appear under **Last hour**. If the app is quiet, open it with **Visit** and select **Refresh**.
## Choose how long to keep logs [#choose-how-long-to-keep-logs]
A longer period costs more for a busy app.
- **1 or 3 days** suit day-to-day checks.
- **7 or 14 days** help when a problem shows up only now and then.
- **30 days** suits an app where you need to look back over a month.
Change the period or turn logs off at any time.
## If something goes wrong [#if-something-goes-wrong]
- **Nothing shows under Last hour**: check that **Keep logs** is on, then give it a minute. An app that **Sleeps when idle** prints nothing while asleep; visit it to wake it.
- **The app prints too much**: lower the period, or have the app log less (for example, only warnings and errors).
- **A new version failed many requests and visitors went back to the one before**: read the logs for those errors, fix them and deploy again.
## Where to go next [#where-to-go-next]
- [Deploy an app](/docs/deploy/deploy-an-app)
- [Run settings and app keys](/docs/deploy/run-settings)
- [Project settings](/docs/projects/settings)