# Testing with generated logs

Want to know how TKTail behaves on *your* machine with *your* kind of load? Use **TKTail Log
Generator** (`TKTailLogGen`), a separate free tool of the TKTail project. It writes
synthetic log files at a rate, record size and format you choose. It is the same generator
our own measurements use; to repeat the published measurements themselves, see
[Benchmarking TKTail on your PC](https://tktail.dev/help/benchmarking/).

It works offline: no network, no telemetry. It writes only the file you name, never replaces
an existing file unless you say so, and stops before your disk runs low.

## Follow a live log

The quickest way is the generator's window:
1. Run **TKTailLogGen.exe**.
2. Choose *Application log*, 1000 lines/s, 500 B, *Duration* 60 seconds.
3. Click **Start + Open in TKTail**.

TKTail opens the file and follows it **LIVE**, while the generator's graph shows the actual
rate.

The same from a console:

1. Start a workload:

   ```
   TKTailLogGen generate -o C:\Temp\live.log --format applog --rate 1000 --line-size 500 --duration 5m
   ```

2. Open `C:\Temp\live.log` in TKTail (`tktail open C:\Temp\live.log`). The tab shows **LIVE**,
   and new lines appear as they are written.
3. The status bar's growth segment shows the rate TKTail sees (about `+1000 lines/s`).

Press **Ctrl+C** in the console to stop early. The generator prints what it actually wrote:
lines, bytes, the actual rate, and whether it could sustain the requested rate.

## A huge file

```
TKTailLogGen generate -o C:\Temp\big.log --format plain --rate max --size 5GB
```

TKTail opens the file at its end at once, whatever its size, and indexes it in the
background.

**Check the space first.** The generator plans every run: it shows the estimated output, the free
space of the volume the file really goes to and the 2 GB that always stay free, and it does not
start a run that would not fit (the window disables Start; the command line stops with exit
code 3). `--dry-run` shows the plan without writing anything:

```
TKTailLogGen generate -o C:\Temp\big.log --format plain --rate max --size 5GB --dry-run
```

A run that reaches the reserve while writing stops by itself, with a complete last record.
Details: Disk safety.

## Alerts

```
TKTailLogGen generate -o C:\Temp\alerts.log --rate 500 --alert-every 1000 --duration 2m
```

Every 1,000th record is an `ERROR` that contains `BENCHMARK_ERROR`. Add an alert rule for
`BENCHMARK_ERROR` in TKTail. After the run, the number of alerts should equal the
"Expected BENCHMARK_ERROR records" line the generator printed.

## Rotation

```
TKTailLogGen generate -o C:\Temp\rot.log --rate 2000 --line-size 300 --rotate-size 20MB --rotate-keep 3 --duration 3m
```

Every 20 MB, the file is renamed to `rot.log.1` and a new `rot.log` starts. TKTail follows the
log by name.

## Errors with stack traces and payloads (multi-line records)

```
TKTailLogGen run multiline-mix-1000 -o C:\Temp\multiline.log
```

Writes 1,000 records/s for 60 s: 80 % one-line records, 10 % errors with an exception and a
stack trace, 10 % requests with a pretty-printed JSON payload - about 2,560 **source lines** per
second. In TKTail, click any line of a stack trace or a payload: the Inspector and the RECORD view
show the whole entry it belongs to, and *Copy Current Record* copies all of its lines.
`--exceptions` and `--payloads` choose other shares; `multiline-exception-1000` and
`multiline-payload-json-1000` are the extreme cases.

## Qlik script reload traces

```
TKTailLogGen run qlik-trace-1000 -o C:\Temp\reload.log
```

Writes 1,000 synthetic Qlik time blocks/s for 60 s: a line holding only the time, then loads
(`Orders << QVD_ORDERS_202610`), `Lines fetched: 25 000`, TRACE lines and now and then the
`END IF` script error - about 4,000 **source lines** per second. TKTail detects it as
[Qlik Script Trace](https://tktail.dev/help/viewing-logs/#qlik-script-trace); click any line of a block to see the
whole block in the Inspector and the RECORD view. The content is generic test data, not a real
reload.

## Good to know

- **Records or lines.** For one-line logs a record is a line. For multi-line records the
  generator always reports both: *1,000 records/s, ~2,560 source lines/s*. TKTail's status bar
  counts source lines.

- **Rate x record size = bytes per second.** 100,000 lines/s at 100 B per record is 10 MB/s.
  At 1 KB per record it is 100 MB/s - 6 GB a minute.
- **Sequence numbers.** Every record carries one (`seq=000000012345`).
  `TKTailLogGen verify <file>` checks that nothing is missing or duplicated.
- **Saved scenarios.** `--save-scenario` saves the settings; `TKTailLogGen run <scenario>`
  repeats them. A scenario holds only workload settings, never paths or personal data.
- **Local results.** What you measure is a result of your machine and disk, not a guarantee.

Everything else: docs/LOG_GENERATOR.md.

---

The HTML page: https://tktail.dev/help/testing-with-generated-logs/
