SIGN IN SIGN UP

feat: add support for FIREBASE_DEBUG_PATH environment variable (#11023)

* feat: add support for FIREBASE_DEBUG_PATH environment variable

### Description
Adds support for the `FIREBASE_DEBUG_PATH` environment variable, allowing users to customize the output location and filename of `firebase-debug.log`. This is especially useful in environments where the current working directory is read-only, in CI/CD pipelines, or when users want to centralize Firebase CLI logs.

Key changes:
- Added `resolveLogTarget()` in `src/logger.ts` to resolve target directories, filenames, extension, and expand `~` home directory paths.
- Updated `findAvailableLogFile()` to automatically create missing parent directories and rotate candidate filenames on permission/lock errors.
- Updated CLI exit error handling in `src/bin/cli.ts` to reference the custom log path if set.
- Updated MCP server initialization in `src/bin/mcp.ts` to respect `FIREBASE_DEBUG_PATH` when configured.
- Added comprehensive unit tests in `src/logger.spec.ts`.
- Added an entry to `CHANGELOG.md`.

### Scenarios Tested
- Default behavior with no `FIREBASE_DEBUG_PATH` set (outputs to `./firebase-debug.log`).
- `FIREBASE_DEBUG_PATH` set to a custom file path (`/tmp/custom/my-debug.log`), verifying parent directory creation and file output.
- `FIREBASE_DEBUG_PATH` set to directory paths with and without trailing slash.
- `FIREBASE_DEBUG_PATH` using `~` home directory expansion.
- Candidate file rotation when the primary log file exists and is not writable.
- MCP server start with `FIREBASE_DEBUG_PATH`.
- Unit test suite (`npx mocha src/logger.spec.ts`) with all 25 tests passing.
- TypeScript compilation and ESLint checks.

### Sample Commands
- `FIREBASE_DEBUG_PATH=/tmp/firebase-debug.log firebase deploy --debug`
- `FIREBASE_DEBUG_PATH=~/logs/firebase/ firebase projects:list --debug`
- `FIREBASE_DEBUG_PATH=./custom-debug.log firebase emulators:start`

* fix: address PR review feedback on error narrowing and env var trimming

* fix(cli): use logFilename directly in help template
J
Joe Hanley committed
c65c607fdf01bc57944e1b7970bad289fd713f91
Parent: 5e5cc63
Committed by GitHub <noreply@github.com> on 9/2/2026, 8:27:44 PM