# Read logs with journalctl

> journalctl reads the logs that systemd collects from the system and from every service, in one searchable place.

URL: https://levelrail.com/learn/server-basics/read-logs-with-journalctl/
Updated: 2026-11-27

A service stops answering. To read its logs on a systemd server, run `sudo journalctl -u servicename -n 50`. You could guess, or you could read what it said just before it failed: the error, the exit code, the line that tells you which file it could not open. On a systemd server that history is in the journal. Learning a handful of journalctl options turns a vague failure into a specific message.

## How it works

[systemd](https://levelrail.com/learn/glossary/#systemd)) starts and supervises services. It captures everything a service prints to its standard output and standard error, plus messages sent through the system log interface, and stores them in a binary journal. The journal records the time, the unit (service) name, a priority level and the message. Because it is indexed, journalctl can filter fast by unit, time, boot or priority.

Messages carry a priority from `emerg` and `alert` through `crit`, `err`, `warning`, `notice` and `info` to `debug`. Filtering with `-p err` shows `err` and anything more severe.

The journal may be volatile, kept in memory under `/run/log/journal` and lost at reboot, or persistent, kept in `/var/log/journal`. On Ubuntu it is normally persistent. Its size is capped by system settings, so very old entries are removed automatically.

Programs that write their own files, such as [nginx](https://levelrail.com/learn/glossary/#nginx)), still write to `/var/log/nginx/`. The journal covers systemd services and the system itself, and you read other logs with `tail` and `less`.

A worked example: your app service `demo` fails after a deploy. You run `sudo journalctl -u demo -n 30 --no-pager`. The last lines say it could not open a config file. You fix the path, run `sudo systemctl restart demo`, then `sudo journalctl -u demo -f` and watch it start cleanly. You read, fix, restart and watch, using the same tool each time.

## Step 1: Read recent logs

```bash
sudo journalctl -n 50
```

`-n 50` shows the last 50 lines. Without it you get every stored entry, oldest first, in a pager.

What you should see: lines that start with a date and time, the host name, the program name with its process ID and a message.

## Step 2: Show logs for one service

```bash
sudo journalctl -u ssh
```

`-u` filters by unit name. On Ubuntu the SSH service is `ssh`. On other systems it may be `sshd`. Add `-e` to jump to the end.

What you should see: only lines from that service, such as login messages. Use `-r` to show the newest first.

## Step 3: Follow logs live

```bash
sudo journalctl -u ssh -f
```

New lines appear as they happen. Press `Ctrl+C` to stop.

What you should see: the last few lines, then the command waits. Log in from another terminal and a new line appears.

## Step 4: Filter by time and level

```bash
sudo journalctl --since "1 hour ago"
sudo journalctl -p err -b
sudo journalctl -u ssh --since "2026-11-27 09:00" --until "2026-11-27 10:00"
```

`--since` and `--until` limit the time range. `-p err` shows only errors and worse, and `-b` limits the output to the current boot.

What you should see: a shorter list, or `-- No entries --` if nothing matches.

## Step 5: Check how much space logs use

```bash
journalctl --disk-usage
```

What you should see: a line such as `Archived and active journals take up` followed by a size. Logs can grow over time (the same worry as in [check disk, memory and CPU usage](https://levelrail.com/learn/server-basics/check-disk-memory-and-cpu-usage/))). Trimming them is a deliberate step, so read the journalctl manual before you run `--vacuum-size` or `--vacuum-time`, which delete old entries.

## Check it worked

After step 1 you should see lines that start with a date, the host name, the program name and a message. After step 3 the command should wait and print new lines as they arrive, for example when you log in again with SSH. For a plain text version that works in scripts, add `--no-pager` and `-o short-iso`, which prints ISO timestamps.

## Edge cases and gotchas

- **Times are shown in the server's time zone.** If the server runs UTC and you think in local time, your `--since` windows will look off. Check `timedatectl`. Add `--utc` to be explicit.
- **The journal can be empty after a reboot.** If the journal is only in memory, the logs before the reboot are gone. Create `/var/log/journal` and restart `systemd-journald`, or set `Storage=persistent` in the journald config, if you want to keep them.
- **Lines may be cut off.** The pager does not wrap long lines. Use `--no-pager` or press the right arrow, and add `-o cat` to print only the message.
- **A service's own file logs are separate.** If a program logs to `/var/log/app.log`, journalctl will not show those lines unless the service also writes to the console.
- **Docker container logs are not in the journal by default.** (See [read container logs](https://levelrail.com/learn/deploy-operate/read-container-logs/)).) Use `docker logs` or `docker compose logs`. Docker's own daemon messages are under `-u docker`.
- **Kernel messages have their own view.** `journalctl -k` shows the kernel ring buffer, which is where out-of-memory kills and disk errors appear.
- **`-u` matches the unit name, not the program.** The service for Docker is `docker`, and for SSH on Ubuntu it is `ssh`. Check with `systemctl list-units --type=service`.
- **Permissions hide other users logs.** A normal user sees only its own entries unless in the `systemd-journal` group.

## Troubleshooting

| Symptom | Likely cause | Fix |
| --- | --- | --- |
| `No journal files were found.` | Journal not stored on disk or you lack access | Try `sudo`, or check the persistent storage setting |
| `-- No entries --` | Filters are too narrow | Widen the time range or check the unit name |
| `systemctl status nginx` says `Unit nginx.service could not be found.` and `journalctl -u nginx` shows no entries | Wrong service name or not installed | List with `systemctl list-units --type=service` |
| Hint that you are not seeing all messages | Your user is not in the right group | Use `sudo` or add yourself to `systemd-journal` |
| Output ends with `lines 1-23` and waits | You are in the pager | Press `q` |
| Logs stop at an old date | The journal was rotated or vacuumed | Check `journalctl --disk-usage` and the size limit |
| Output too wide to read | Long lines in the pager | Add `--no-pager` or `-o cat` |
| Cannot find old logs after reboot | Journal is volatile | Make it persistent, see the gotchas above |

## Real-world scenario

Nina deploys an update and the site returns errors. The service is called `webapp`. She runs `sudo systemctl status webapp` and sees `activating (auto-restart)`, so it keeps crashing. She runs `sudo journalctl -u webapp -n 40 --no-pager` and finds `Error: EADDRINUSE`, which means another process holds the port.

She checks with `sudo ss -ltnp` and finds an old copy of the app still running. She stops it, restarts the service, and `journalctl -u webapp -f` shows a clean start.

Without the journal she would have guessed. With it she read the answer in the first screen.

## Quick reference

| Task | Command |
| --- | --- |
| Last 50 lines | `sudo journalctl -n 50` |
| One service | `sudo journalctl -u ssh` |
| Follow live | `sudo journalctl -u ssh -f` |
| Since a time | `sudo journalctl --since "1 hour ago"` |
| Errors this boot | `sudo journalctl -p err -b` |
| Previous boot | `sudo journalctl -b -1` |
| Kernel messages | `sudo journalctl -k` |
| Space used | `journalctl --disk-usage` |

## Security and safety notes

- `--vacuum-size` and `--vacuum-time` delete log history for good. Do not run them while you are still investigating a problem.
- Logs can contain passwords, tokens or personal data. Check before you paste them into a public forum.

## Related lessons

- [Run a service with systemd](https://levelrail.com/learn/server-basics/run-a-service-with-systemd/)): where service logs come from
- [Read container logs](https://levelrail.com/learn/deploy-operate/read-container-logs/)): the Docker side
- [Limit Docker log size](https://levelrail.com/learn/deploy-operate/limit-docker-log-size/)): keep logs from growing without end
- [Fix 502 Bad Gateway](https://levelrail.com/learn/deploy-operate/fix-502-bad-gateway/)): logs are the first stop

## Next

[Run a service with systemd](https://levelrail.com/learn/server-basics/run-a-service-with-systemd/)).

## Frequently asked questions

### Why do I get no entries or a permission message?

Normal users may only see their own logs. Use sudo, or add your user to the systemd-journal group.

### How do I leave the log view?

Press q. The output opens in a pager, so you can also scroll with the arrow keys and search with a slash.

### Do logs survive a reboot?

Only if the journal is stored on disk. On some systems it is kept in memory and lost at reboot. Check for the /var/log/journal folder, and ask for the previous boot with journalctl -b -1.

### Where are the logs of my Docker containers?

Docker keeps its own container logs, read with docker logs. The journal shows the Docker service itself. See the container logs lesson.


## Sources

- [journalctl manual](https://www.freedesktop.org/software/systemd/man/latest/journalctl.html)
