Skip to content

[wrangler] Lazily resolve WRANGLER_LOG_PATH on first write - #16947

Closed
umeraamir69 wants to merge 1 commit into
cloudflare:mainfrom
umeraamir69:fix/wrangler-log-path-lazy-16925
Closed

umeraamir69 wants to merge 1 commit into
cloudflare:mainfrom
umeraamir69:fix/wrangler-log-path-lazy-16925

Conversation

@umeraamir69

@umeraamir69 umeraamir69 commented Nov 16, 2026 •

Copy link
Copy Markdown

Fixes #16925.

debugLogFilepath was computed once at module evaluation time, so setting process.env.WRANGLER_LOG_PATH in vite.config.ts after a static import { cloudflare } from "@cloudflare/vite-plugin" had no effect. Resolve and memoize the path on first access via getDebugLogFilepath(), matching how WRANGLER_WRITE_LOGS is read lazily in shouldLogToDisk().


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: bugfix for existing env var behavior; no API or docs change

Devin Review

Setting the env var in vite.config.ts after a static import of
@cloudflare/vite-plugin was ignored because debugLogFilepath was
computed at module evaluation time. Resolve and memoize on first
access instead, matching WRANGLER_WRITE_LOGS.
@changeset-bot

changeset-bot Bot commented Nov 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6495b44

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
wrangler Patch
@cloudflare/vitest-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

Copy link
Copy Markdown
Contributor

Hi @umeraamir69. Thanks for taking the time to contribute to Workers SDK.

This PR has been automatically closed because you are not currently a registered (vouched) collaborator for this repository.

AI tools now let our team generate proposed code changes quickly. Reviewing changes, checking that they solve the right problem, and maintaining code quality over time still take substantial care and effort. We therefore limit PRs to registered collaborators so we can focus that effort where it is most useful.

For the majority of external contributors, the most effective way to help is through issues: describing a problem or use case, providing a minimal reproduction, investigating its cause, or helping us verify a fix. Those contributions help us understand what needs to change and are very welcome.

We will take an initial look at this PR and decide whether it is something we want to invest time in reviewing and maintaining. We may reopen it if we decide to proceed, but we cannot guarantee that it will be reopened or receive a full review.

@github-actions github-actions Bot closed this Nov 16, 2026
@github-project-automation github-project-automation Bot moved this from Untriaged to Done in workers-sdk Nov 16, 2026
@workers-devprod
workers-devprod requested review from a team and dario-piotrowicz and removed request for a team November 16, 2026 06:39
@workers-devprod

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • .changeset/wrangler-log-path-lazy.md: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/utils/log-file.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/index.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/utils/log-file.ts: [@cloudflare/wrangler]

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 3 potential issues.

Devin Review

* `@cloudflare/vite-plugin` — is still respected. Matches the lazy read of
* `WRANGLER_WRITE_LOGS` in `shouldLogToDisk()`.
*/
let cachedDebugLogFilepath: string | undefined;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 New module-wide mutable log-path cache

cachedDebugLogFilepath introduces mutable module-wide state shared by the getter and test reset function. The code-quality rule prohibits introducing global variables.

Learn more

The memoized path is now stored in a mutable module-level binding. Both the production getter and the exported test helper modify it, which conflicts with the repository's prohibition on new global variables.

Example: The first getter call fills the shared binding; resetDebugLogFilepathForTests() later clears that same binding for every caller.

Recommended fix: Encapsulate the cached value in a closure or logging-state instance, preserving lazy resolution and a stable path across writes. Keep test reset access within that encapsulation.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +98 to +100
export function getDebugLogFilepath(): string {
return (cachedDebugLogFilepath ??= getDebugFilepath());
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Exported getter lacks attached JSDoc

getDebugLogFilepath has no attached JSDoc; the preceding documentation belongs to the cache declaration. The implementation conventions require JSDoc for exported functions.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.


Fix `WRANGLER_LOG_PATH` being ignored when set in `vite.config.ts` after a static import of `@cloudflare/vite-plugin`

The debug log filepath is now resolved lazily on first write (memoized), matching how `WRANGLER_WRITE_LOGS` is read. Setting `process.env.WRANGLER_LOG_PATH` in the Vite config body after importing the plugin now writes logs to the configured path instead of the global default directory.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Changeset includes internal caching details

The memoization explanation and WRANGLER_WRITE_LOGS comparison describe implementation details excluded by the changeset guidance. The following sentence already explains the user-facing benefit.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

WRANGLER_LOG_PATH is resolved at import time, so setting it in vite.config.ts is ignored with @cloudflare/vite-plugin

2 participants