# Log collection

> The device's system and service logs, read by the sensor and analyzed in the realm against the shipped ruleset, with the lines that match a rule raised as alerts.

Most attacks show up in logs first: failed sign-ins, new accounts, a service restarted at 3 a.m. The sensor reads
each device's logs and sends what it reads to the realm, where it's analyzed, and the lines that match a rule become
alerts.

## Before you begin

- **Who:** an administrator of the realm, in a group holding `RealmOwner` or `RealmViewer` on the realm or a realm
  above it (see [Delegated administration](../../../platform/realms/delegated-administration/)). Reading needs no
  more than `RealmViewer`; adding logs is a [group configuration](../../sensors/group-configuration/) change.
- **Where:** the API.
- **First:** an enrolled device.

## How it works

When the sensor is installed, it picks the logs the device has:

| System | Logs read |
|---|---|
| Linux | The system journal or syslog files, the authentication log, and the logs of a web server, database or audit service where one is installed |
| macOS | The unified log's entries for `sudo`, SSH, screen sharing, sign-out, privacy permission changes and security sessions |

It also reports, on a schedule, the device's disk usage and listening ports, and on Linux its recent sign-ins. The
device client's own log is read too, so a restart you asked for, and each start of the client with its reason, show
up as alerts.

Each line is analyzed against the realm's ruleset. A line that matches a rule raises an alert; a line that matches
none isn't kept.

## Set it up

Nothing to turn on. Alerts appear in the [Security events](../../security-log/events/) API. To read more logs, add them in the realm's
[group configuration](../../sensors/group-configuration/) (see
[Logs](../../sensors/configuration-reference/#logs-localfile) in the configuration reference). To see which logs one
device reads now, and how many events each has sent, open its [device view](../../security-log/device-view/).

## Limits and defaults

| Limit | Default | Can you change it? |
|---|---|---|
| Logs read | Those the device has at install | Add log files in the group configuration |
| Formats | Plain lines, JSON lines, the Linux system journal | No others |
| Ruleset | The shipped ruleset | Your own rules are [planned](../whats-next/#custom-detection-rules) |

## Good to know

- **Only what's there.** A default log is added only when the device has it at install.
- **No commands from the realm.** The group configuration can add log files, but not logs read from a command's
  output: a configuration that would run a command on your devices is refused.

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| A log you added raises nothing | No rule in the shipped ruleset matches its lines | Expected until your own rules arrive; check the device view's **Stats** to see its events are read |
| A log you added doesn't show in the device's configuration | The device hasn't received the change | See [Group configuration](../../sensors/group-configuration/#troubleshooting) |

## Audit record

Alerts are kept in the [security log](../../security-log/events/); reading them writes no audit record.

## Related

- [Security events](../../security-log/events/): where the alerts land.
- [Threat mapping](../threat-mapping/): what each alert means in ATT&CK terms.
