# Logging

The server writes what it does to a log file, `CrushMFT.log`, and can send the same, or a tidier record of the events that matter, to other places. The Logging section of [Preferences](Prefs.md) decides how much is logged, where the files are, how long they are kept, and where else it goes.

![The Logging section, on its Settings tab](Prefs-Logging/section.png)

| Tab | Holds |
|---|---|
| [Settings](#settings) | the log file: on or off, how detailed, where, how it is rolled, how long things are kept |
| Log Targets | sending the log, or events for a SIEM, to syslog, a database, a file or the console, see [Log targets](Prefs-Logging-Targets.md) |
| [Metrics](#metrics) | numbers for Prometheus |
| Log File Options | which kinds of lines are written at all, see [What is logged](Prefs-Logging-Events.md) |

**Save** at the bottom saves all four tabs ([saving](Prefs.md#saving)).

## Settings

![The Settings tab](Prefs-Logging/settings.png)

### Logging

| Setting | What it does | Default |
|---|---|---|
| **Enable logging** | writes the log file. Off: `CrushMFT.log` is not written. | on |
| **Log transfer speeds** | the line for a finished transfer also says how fast it went | on |
| **Keep separate session logs** | besides the main log, every session gets a log file of its own | on |
| **Send DMZ log messages to Internal server too** | on a DMZ server: its log lines are also passed to the internal server, so that both logs are in one place | off |
| **Debug socket logging** | logs the opening and closing of network connections. For finding a fault, with support. | off |
| **Log debug level** | how detailed the log is: 0 for normal work, 1 for errors that explain more, 2 for a verbose log. A digit from 0 to 9. | 0 |
| **Filter log messages matching** | patterns, separated by commas. A line that fits one of them is left out of the log. `*` stands for any text. | empty |

Level 2 and above writes a great deal, and can put what users send into the log. Turn it up to find a fault, and back down afterwards.

### Log Files

| Setting | What it is | Default |
|---|---|---|
| **Log file location and name** | the main log file | `./CrushMFT.log`, in the server's folder |
| **User session log location** | the folder for the session logs | `./logs/session_logs/` |
| **Job logs file name** | how the log of a job run is named. `{scheduleName}` is the name of the job, `{id}` the number of the run. | `{scheduleName}_{id}.log` |

### Rolling

Rolling closes the log file, moves it into the folder `logs` beside it under a name with the date, and starts a new one.

| Setting | What it does | Default |
|---|---|---|
| **Enable log rolling** | turns rolling on | on |
| **Enable daily log rolling** | rolls once a day, at the roll time. Off: rolls whenever the file is larger than **Max size before rolling**, which is then shown. | on |
| **Max size before rolling** | the size in MB at which the file is rolled, when daily rolling is off | 10 |
| **Keep how many files** | how many rolled files are kept in the `logs` folder. The oldest are deleted. 0: no limit. | 30 |
| **Log roll time** | the time of day of the daily roll, as hours and minutes | `00:00` |
| **Log roll rename hours** | a number of days to add to the date in the name of the rolled file. -1 names a file that is rolled just after midnight after the day it covers. Despite its name, it counts days. | 0 |
| **Log roll date format** | how the date in the name is written: `yyyy` year, `MM` month, `dd` day, `HH` hour, `mm` minute, `ss` second | `yyyyMMdd_HHmmss` |

A rolled file is named like the log file with the date behind it, such as `CrushMFT.log_20261120_235910.log`.

### Log Buffer

| Setting | What it is | Default |
|---|---|---|
| **Log buffer memory** | how much of the log the server gathers in memory before it writes it to the file, in bytes or KB. 0: not set, each line is written as it comes. A buffer makes a very busy server faster and means the last lines can be missing after a crash. | 0 |
| **User log buffer** | how many lines of each session's log are kept in memory | 500 lines |

### Days To Hold

How many days the server keeps each of these before it deletes them.

| Setting | What it is | Default |
|---|---|---|
| **Recent session logs** | the session log files | 7 |
| **Recent job logs** | the log files of job runs | 7 |
| **Recent job history** | the records of job runs that the Jobs app shows | 7 |
| **Temporary job logs**, **Temporary job history** | the same for jobs that were not saved, such as test runs | 7 |

The main log is not part of this: how much of it is kept is the number of rolled files above.

## Metrics

The server can publish numbers about itself for Prometheus: sessions, logins, transfers, memory, queues and more. An Enterprise licence is needed.

![The Metrics tab](Prefs-Logging/metrics.png)

| Setting | What it is | Default |
|---|---|---|
| **Publish Prometheus metrics** | turns the metrics on. Counters start from zero at that moment. | off |
| **Path** | the address the metrics are read from, on every HTTP and HTTPS listener | `/metrics` |
| **Bearer token** | a secret the reader must send. **Generate** makes one. | empty |
| **Allowed IPs** | the addresses that may read the metrics, separated by commas, with `*` for any part | empty |

Metrics are only handed out with a token, an address list, or both. With neither, the server refuses, so that they are never open by accident.

The tab shows the lines to put into `prometheus.yml`, with this server's address filled in. The metrics hold no user names, paths or addresses.
