# Folder formats: local configuration (.tktail)

Tell TKTail once that "the logs in this folder are Qlik traces" (or JSON Lines, or your own
custom format), and every file in that folder and its subfolders opens that way. The setting
lives in a small file named `.tktail` next to the logs - like `.editorconfig`, but for how
TKTail reads log files. A closer `.tktail` wins over one further up, and a format you pick with
**View As** always wins for the current session.

## Quick start

1. Open a log from the folder.
2. **View > View As > Set Format for This Folder...** (the same menu opens from the **Format**
   button in the RECORD view's header), pick the format, **Save**. The dialog says which file it
   writes.

*Screenshot: Set Format for This Folder: the format list and the .tktail it writes*

3. TKTail writes `.tktail` in the file's folder. The file - and every file opened later in that
   folder or below it - uses that format. The Inspector's **Resolution** row says
   *Folder configuration*, **Configuration** names the `.tktail`, and **Auto detector** shows
   what the content alone says. The RECORD view's Format button reads `Auto (<format>)`; its
   tooltip names the `.tktail` too.

*Screenshot: A Qlik reload trace configured by T:\Logs\Qlik\.tktail: Inspector rows Format, Resolution, Configuration, Rule and Auto detector; the RECORD view shows the time block around the caret*

TKTail never creates a `.tktail` on its own: opening a file, browsing a folder or detecting a
format reads `.tktail` files but writes nothing. Only the actions below write one.

## What the file looks like

A Qlik folder (`root: true` - nothing above this folder applies):

```json
{
  "schemaVersion": 1,
  "root": true,
  "defaults": {
    "format": "builtin:qlik-script-trace"
  }
}
```

A mixed folder:

```json
{
  "schemaVersion": 1,
  "defaults": {
    "format": "builtin:applog"
  },
  "rules": [
    { "match": "*.jsonl", "format": "builtin:jsonl" },
    { "match": "reload-*.log", "format": "builtin:qlik-script-trace" }
  ]
}
```

| Setting | Meaning |
|---|---|
| `schemaVersion` | `1`. A file from a newer TKTail is ignored (and reported), never guessed at |
| `root` | `true`: `.tktail` files in the folders above do not apply here (a project or repository root). Optional |
| `defaults.format` | The format for every file in this folder and below, unless a rule or a closer `.tktail` says otherwise. Optional |
| `rules` | `match` (a file name or a pattern) and `format`, in order. Optional |

The file is UTF-8 JSON, at most 256 KB and 1,000 rules. Settings this version does not know are
kept when TKTail edits the file, and listed as warnings.

## Format ids

A `.tktail` names formats by a stable id, never by the name shown in the menus (names may
change; ids do not):

| Id | Format |
|---|---|
| `builtin:text` | Plain Text |
| `builtin:applog` | Application log + stack traces |
| `builtin:jsonl` | JSON Lines / NDJSON |
| `builtin:qlik-script-trace` | Qlik Script Trace |
| `builtin:<key>` | any built-in format: the keys are in `tktail formats list` |
| `custom:<id>` | a custom format profile by its id (`custom:rest.api`) - renaming the profile keeps it working |

## Rules and patterns

Patterns are relative to the folder of the `.tktail` and ignore letter case:

| Pattern | Matches |
|---|---|
| `reload.log` | a file with this name, in this folder or any folder below |
| `*.log`, `qlik-*.log`, `trace-??.txt` | file names; `*` is any text, `?` one character |
| `archive/*.log` | `.log` files directly in `archive` (below the `.tktail` folder) |
| `archive/**/*.log` | `.log` files in `archive` and any folder below it |

`\` works like `/`. Absolute paths and `..` are not allowed: a `.tktail` only describes files
below its own folder. **When several rules in one file match, the last one wins** - put general
rules first and exceptions after them.

## Folders and subfolders

```
C:\Logs\.tktail                default: Application log
C:\Logs\Qlik\.tktail           default: Qlik Script Trace; rule raw.log -> Plain Text
C:\Logs\Qlik\reload.log        -> Qlik Script Trace   (Folder configuration)
C:\Logs\Qlik\raw.log           -> Plain Text          (File rule)
C:\Logs\Qlik\2026\old.log      -> Qlik Script Trace   (Inherited configuration)
C:\Logs\api.log                -> Application log     (Folder configuration)
```

- A `.tktail` changes only what it says. A child folder whose `.tktail` has a single rule still
  inherits its parent's default for every other file.
- **Set Format for This Folder** in a subfolder writes that subfolder's own `.tktail` - the
  parent's file is not touched.
- `"root": true` stops the search upwards.
- Network shares (`\\server\share\...`) work the same way; the search stops at the share.

## The order TKTail follows

For every file, the first of these that applies decides:

1. A format you chose with **View As** in this session (or `tktail open --format`).
2. The nearest `.tktail`: its last rule that matches the file.
3. The nearest `.tktail`: its folder default.
4. The `.tktail` files further up, nearest first, until one with `"root": true`.
5. A custom format profile that names files like this one (its extensions / file names).
6. Content detection.
7. File-name hints.
8. For the new file of a [rotating dated log](https://tktail.dev/help/rotating-dated-logs/) whose content says nothing yet (it is often
   empty when it becomes LIVE): the format its previous file was read with - until its own content decides.
9. Plain Text.

A configured format that is not available - a custom profile that is not installed or is
disabled - is reported (Problems, Inspector) and the next step decides.

## Doing it from TKTail

**View > View As** (also from the Inspector's Format row and the status bar's format):

| Item | What it does |
|---|---|
| **Auto (Effective Configuration)** | Drops a View As choice: the order above decides again |
| **Set Format for This File...** | Adds a rule for this file's name to its folder's `.tktail` (an earlier rule for the same name is replaced) |
| **Set Format for This Folder...** | Sets (or removes) the folder default in this file's folder |
| **Add Local Format Rule...** | A pattern and a format; the dialog lists the files of the folder the pattern matches |
| **Edit Local Configuration...** | The folder default, the rules (add, edit, remove, reorder) and *Root configuration*, for the `.tktail` that decides the current file (or the file's folder) |
| **Explain Format Resolution...** | Every step of the order above for this file - what each `.tktail` says, what was used, what the content detector says |
| **Detect from Content...** | What the content alone says (View As and `.tktail` ignored), with *View As* that format for this session |

- Writes are safe: TKTail writes a temporary file and replaces `.tktail` in one step, keeps
  settings it does not know, and never overwrites a `.tktail` it cannot read (fix or delete
  that one first).
- Set Format for This File / Folder also drops a View As choice of the current file, so you see
  the saved format at once.
- The log files themselves are never changed.

When a `.tktail` changes - from TKTail, an editor or `git pull` - open files follow within about
two seconds. A file you chose a format for with **View As** keeps it; its Inspector notes that
the configuration changed.

## Custom formats

A custom profile is chosen in the same dialogs (they list the profiles in force), or from the
Custom Format Studio: **Use For > Apply to Current File / Set as Folder Default / Add Folder
Rule...** for the saved profile. The `.tktail` stores its id (`custom:rest.api`). Renaming the profile keeps the association; a
`.tktail` that names a profile this computer does not have falls back to the next step and says
so.

## Seeing why

- **Inspector > TKTail**: *Format* (configured / detected / chosen), *Resolution* (the source),
  *Configuration* and *Rule* (when a `.tktail` decided), *Auto detector* (what the content
  says - "differs" when it disagrees). Click *Resolution* for the full explanation, click
  *Configuration* to edit it.
- `tktail formats resolve <file>` prints the same explanation; `tktail formats detect <file>`
  shows content detection only.
- `tktail config validate <folder or file>` checks a `.tktail`.

## When something is wrong

- **A `.tktail` with a mistake** (not JSON, a format id that does not exist, `..` in a pattern)
  is ignored as a whole; the folders above and detection decide. *Problems* shows
  *Local configuration ignored - ...*; `tktail config validate` says what is wrong.
- **The wrong format** for one file: **View As > Plain Text** always shows the raw file. Then
  **Explain Format Resolution** tells which `.tktail` and rule chose it.
- **Safe mode** (`--safe-mode`) does not read `.tktail` files.

## Security

A `.tktail` only describes data: format ids and file name patterns. It cannot run anything - no
commands, scripts, programs or libraries, no includes and nothing fetched from a network - so a
repository can carry one safely. TKTail reads it with a size limit and treats anything it does
not understand as an error or a kept-but-unused setting.

---

The HTML page: https://tktail.dev/help/local-configuration/
