# tmuxp.log.setup_log_file

- **Module:** tmuxp.log
- **Package:** tmuxp
- **Language:** Python
- **Kind:** function
- **Source:** https://github.com/tmux-python/tmuxp/blob/153acdf6ff1268b14d3d03ed488f545a7123c8f1/src/tmuxp/log.py#L240
- **Page:** https://libtmux.org/en/py/latest/workspace/reference/tmuxp-log-setup_log_file/

```
tmuxp.log.setup_log_file(log_file: str, level: str = "INFO") -> None
```

Attach a file handler to the tmuxp logger.

## Parameters

- `log_file` (str): Path to the log file.
- `level` (str): Log level name (e.g. "DEBUG", "INFO"). Selects formatter and sets
handler filtering level.

## Example

```python
>>> import tempfile, os, logging
>>> f = tempfile.NamedTemporaryFile(suffix=".log", delete=False)
>>> f.close()
>>> setup_log_file(f.name, level="INFO")
>>> tmuxp_logger = logging.getLogger("tmuxp")
>>> tmuxp_logger.handlers = [
...     h for h in tmuxp_logger.handlers if not isinstance(h, logging.FileHandler)
... ]
>>> os.unlink(f.name)
```
