diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index fb9522de734ad..18be576841a5c 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -82,7 +82,7 @@ jobs: CLOUDFLARE_ACCOUNT_ID: ${{ secrets.TEST_CLOUDFLARE_ACCOUNT_ID }} WRANGLER: pnpm --silent --package ${{ steps.find-wrangler.outputs.dir}} dlx wrangler NODE_OPTIONS: "--max_old_space_size=8192" - WRANGLER_DEBUG_LOG: ${{ runner.temp }}/wrangler-debug-logs/ + WRANGLER_LOG_DIR: ${{ runner.temp }}/wrangler-debug-logs/ - name: Upload debug logs if: always() diff --git a/.github/workflows/pullrequests.yml b/.github/workflows/pullrequests.yml index 5ca23991678e5..e2d3a6878599e 100644 --- a/.github/workflows/pullrequests.yml +++ b/.github/workflows/pullrequests.yml @@ -115,7 +115,7 @@ jobs: TMP_CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} TMP_CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} NODE_OPTIONS: "--max_old_space_size=8192" - WRANGLER_DEBUG_LOG: ${{ runner.temp }}/wrangler-debug-logs/ + WRANGLER_LOG_DIR: ${{ runner.temp }}/wrangler-debug-logs/ - name: Upload debug logs if: always() diff --git a/packages/wrangler/src/environment-variables/factory.ts b/packages/wrangler/src/environment-variables/factory.ts index 826b651cd8130..83359581b4a6d 100644 --- a/packages/wrangler/src/environment-variables/factory.ts +++ b/packages/wrangler/src/environment-variables/factory.ts @@ -13,8 +13,8 @@ type VariableNames = | "WRANGLER_C3_COMMAND" | "WRANGLER_CF_AUTHORIZATION_TOKEN" | "WRANGLER_CLIENT_ID" - | "WRANGLER_DEBUG_LOG" | "WRANGLER_LOG" + | "WRANGLER_LOG_DIR" | "WRANGLER_REVOKE_URL" | "WRANGLER_SEND_METRICS" | "WRANGLER_TOKEN_URL"; diff --git a/packages/wrangler/src/utils/debug-log-file.ts b/packages/wrangler/src/utils/debug-log-file.ts index b37a49defffd8..9c1cffb91d244 100644 --- a/packages/wrangler/src/utils/debug-log-file.ts +++ b/packages/wrangler/src/utils/debug-log-file.ts @@ -5,26 +5,29 @@ import { getEnvironmentVariableFactory } from "../environment-variables/factory" import { getBasePath } from "../paths"; import type { LoggerLevel } from "../logger"; -const getDebugFilepath = getEnvironmentVariableFactory({ - variableName: "WRANGLER_DEBUG_LOG", - defaultValue: () => { - const date = new Date() - .toISOString() - .replaceAll(":", "-") - .replace(".", "_") - .replace("T", "_") - .replace("Z", ""); - const absoluteFilepath = path.join( - getBasePath(), - ".wrangler", - "debug-logs", - `wrangler-debug-${date}.log` - ); - - return absoluteFilepath; - }, +const getDebugFileDir = getEnvironmentVariableFactory({ + variableName: "WRANGLER_LOG_DIR", }); +function getDebugFilepath() { + const dir = + getDebugFileDir() ?? path.join(getBasePath(), ".wrangler", "debug-logs"); + + const date = new Date() + .toISOString() + .replaceAll(":", "-") + .replace(".", "_") + .replace("T", "_") + .replace("Z", ""); + + const filepath = dir.endsWith(".log") + ? dir // allow the user to provide an exact filepath + : path.join(dir, `wrangler-debug-${date}.log`); + + // use path.resolve to allow the user-provided env var to be a relative path + return path.resolve(filepath); +} + async function ensureDirectoryExists(filepath: string) { const dirpath = path.dirname(filepath);