# Logging (?46)

> Start or stop logging the session to a file, in an xterm built to log; DECGPBM on a VT340.

- **Sequence:** `CSI ? 46 h`
- **xterm:** [Functions using CSI](https://invisible-island.net/xterm/ctlseqs/ctlseqs.html)

`CSI ? 46 h` starts xterm logging everything it receives to a file, and
`CSI ? 46 l` stops it; [OSC 46](https://control-codes.page/osc/logfile/index.html.md) names the file. DEC used the
same number on its VT340 for DECGPBM, Graphics Print Background Mode,
which xterm takes it to mean instead when it emulates a terminal with
ReGIS graphics.

A default xterm has neither. Logging is compiled in only with
`--enable-logging`, and even then a program can turn it on and off only if
xterm was also built with `ALLOWLOGFILEONOFF`; otherwise the sequence rings
the bell twice and DECRQM reports the mode as permanently set or reset. The
graphics printing that DECGPBM controls is compiled in only with ReGIS
graphics, which is off too
([`dpmodes`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/charproc.c#L7709-L7731),
[`do_dec_rqm`](https://github.com/ThomasDickey/xterm-snapshots/blob/xterm-411a/misc.c#L5594-L5609)).
So a default xterm does not recognize mode `46` at all: it ignores
`CSI ? 46 h` and answers DECRQM for it with `0`.

libghostty-vt does not have the mode either, and does the same. The cases
pass.

## Validation

### XTLOGGING-1: Not recognized

Input, one step per line:

```text
\e[?46$p
\e[?46h
\e[?46$p
```

Expected screen:

```text
|______|
reply \e[?46;0$y\e[?46;0$y
```

### XTLOGGING-2: Nothing happens

Input, one step per line:

```text
A
\e[?46h
B
\e[?46l
```

Expected screen:

```text
|AB____|
cursor 1,3
bell 0
```

---

This is the Markdown version of <https://control-codes.page/modes/logging/>. On that page every validation case runs live in libghostty-vt, the terminal emulation core of Ghostty, compiled to WebAssembly.

The validation cases are written in the notation described in <https://control-codes.page/notation/index.html.md>.
