Storybook logging โ
This document explains how to capture Storybook output to disk for easier debugging and reviews.
Where logs go โ
Logs are written to logs/storybook/.
- Default interactive dev log:
logs/storybook/storybook.log - Debug variant:
logs/storybook/debug-storybook.log - Build log:
logs/storybook/build-storybook.log - Dated logs:
logs/storybook/2026-01-02_12-00-00-storybook.log(ISO date/time)
Note: the
logs/directory is ignored by git (see.gitignore).
NPM scripts โ
We've added convenience scripts to package.json:
npm run storybookโ unchanged, starts Storybook interactively (no log redirection)npm run storybook:logโ starts Storybook interactively (uses a pty viascriptwhen available) and writes stdout/stderr tologs/storybook/storybook.log(colors stripped by default)npm run storybook:debug-logโ starts Storybook with a pty and writes tologs/storybook/debug-storybook.log(preserves ANSI colors)npm run storybook:dated-logโ starts Storybook interactively and writes to a timestamped log file (colors stripped by default)npm run build-storybook:logโ runs a build and writes output tologs/storybook/build-storybook.log(colors stripped)npm run storybook:tailโ tails the defaultstorybook.logfile
Notes on behavior:
- The log scripts use the
scriptutility to allocate a pseudo-TTY so Storybook prompts (e.g., "run on port 6007 instead?") are answerable while the session is captured. - By default, color output is removed to avoid ANSI escape sequences in logs (use
--debugor--preserve-colorflags to keep colors). - If
scriptis not available on the host, the scripts fall back to a non-PTY capture with a warning; in that case prompts may not be answerable. - Windows does not always include
script; see notes below for cross-platform options.
Helper script โ
A helper script is available at scripts/start-storybook-logs.sh which accepts the flags:
--debug(preserve colors)--preserve-color(alias for --debug)--dated--file <name>
Examples:
bash
# start and write to the debug file (preserve ANSI colors)
./scripts/start-storybook-logs.sh --debug
# start and write to a date-stamped file (colors stripped)
./scripts/start-storybook-logs.sh --dated
# explicitly preserve colors when writing to a file
./scripts/start-storybook-logs.sh --preserve-color --file my-run.log
# start Storybook interactively (you can answer prompts) and capture the terminal session to a log (requires `script`)
./scripts/start-storybook-logs.sh --interactive
# interactive with dated file
./scripts/start-storybook-logs.sh --interactive --datedNotes:
- The
--interactiveflag uses thescriptutility to give Storybook a pseudo-tty so interactive prompts (like "run on port 6007 instead?") will work while the session is captured to a log file. - If
scriptis not available, the helper will exit with an error telling you how to install it.
Choosing dated vs single-file logs โ
- Use
storybook:dated-log(or--dated) when you want a separate file per run for historical inspection. - Use
storybook:logfor a single consolidated log file that's easy to tail.