# Debug System
This document describes how debug output works in `string_pipeline`.
## Contents
- [Overview](#overview)
- [Enable Debug Output](#enable-debug-output)
- [Output Channels](#output-channels)
- [Output Structure](#output-structure)
- [Example](#example)
- [Common Workflows](#common-workflows)
- [Notes](#notes)
## Overview
Debug mode shows:
- template/session boundaries
- section-level processing for multi-template input
- cache events (`FAST SPLIT`, `CACHE HIT`, `CACHE MISS`)
- per-operation input/result/timing
- `map` item processing and sub-pipeline steps
- final result timing and cache sizes
Debug output is intended for interactive analysis during template development and troubleshooting.
## Enable Debug Output
You can enable debug mode in two ways.
### Inline debug flag
Add `!` immediately after `{`:
```bash
### CLI debug flag
Use `--debug` (or `-d`):
```bash
### Quiet mode interaction
`--quiet` suppresses debug logs, even when debug is enabled inline or with `--debug`.
```bash
## Output Channels
- final formatted value -> `stdout`
- debug lines -> `stderr`
This allows redirecting debug logs independently from the final output.
## Output Structure
The current debug output has a tree-style layout.
### 1) Session header
Includes template string, input, and section counts.
```text
DEBUG: 📂 MULTI-TEMPLATE
DEBUG: ├── 🏁 MULTI-TEMPLATE START
DEBUG: ├── 1 sections (literal: 0, template: 1)
```
### 2) Section and cache lines
Each template section is listed, then cache behavior is reported.
```text
DEBUG: ├── 📊 SECTION 1/1: [template: split(',', ..) | map { operations: [upper] } | join { sep: "-" }]
DEBUG: ├── 💾 CACHE MISS computing section
```
### 3) Pipeline operations
Shows operation list plus per-step input/result/timing.
```text
DEBUG: │ ├── 🚀 PIPELINE START: 3 operations
DEBUG: │ ├── 1. Split(',')
DEBUG: │ ├── 2. Map(1)
DEBUG: │ ├── 3. Join('-')
DEBUG: │ ├── ⚙️ Step 1: Split
DEBUG: │ │ ├── ➡️ Input: String(hello,world)
DEBUG: │ │ ├── 🎯 Result: List["hello", "world"]
DEBUG: │ │ └── Time: ...
```
### 4) Map item sub-pipelines
For `map`, each item is traced with its own sub-pipeline.
```text
DEBUG: │ │ ├── 🗂️ Item 1/2
DEBUG: │ │ │ ├── ➡️ Input: "hello"
DEBUG: │ │ │ ├── 📂 Sub-Pipeline
DEBUG: │ │ │ │ ├── 🔧 SUB-PIPELINE START: 1 operations
DEBUG: │ │ │ │ ├── ⚙️ Step 1: Upper
DEBUG: │ │ │ │ └── Time: ...
DEBUG: │ │ │ └── Output: "HELLO"
```
### 5) Session footer
Final section includes total elapsed time and cache sizes.
```text
DEBUG: ├── 🏁 ✅ MULTI-TEMPLATE COMPLETE
DEBUG: ├── 🎯 Final result: "HELLO-WORLD"
DEBUG: ├── Total execution time: ...
DEBUG: └── Cache stats: <regex_count> regex patterns, <split_count> split operations cached
```
## Example
```bash
Final output (`stdout`):
```text
HELLO-WORLD
```
Debug output (`stderr`) contains the tree structure shown above.
## Common Workflows
### Verify operation ordering
```bash
### Check cache reuse in multi-template input
```bash
Look for `CACHE HIT` on repeated sections.
### Keep result-only output while forcing debug mode
```bash
Useful in scripts where debug might be enabled but logs should stay suppressed.
## Notes
- Parse failures happen before execution, so step-level debug output is not available for invalid templates.
- Timing values depend on hardware, OS scheduling, and load.
- Debug output format is intended for humans and may change between versions.
Related documentation:
- `docs/template-system.md`
- `docs/command-line-options.md`
- `docs/benchmarking.md`