Skip to content

Commit 35710e5

Browse files
authoredFeb 12, 2025··
fix: respect WRANGLER_LOG in dev (#8061)
* fix debug issue * changeset * add logger.resetLoggerLevel() * add WRANGLER_LOG test
1 parent 1b07419 commit 35710e5

File tree

6 files changed

+31
-69
lines changed

6 files changed

+31
-69
lines changed
 

‎.changeset/wicked-pets-jump.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
fix: respect `WRANGLER_LOG` in `wrangler dev`
6+
7+
Previously, `--log-level=debug` was the only way to see debug logs in `wrangler dev`, which was unlike all other commands.

‎packages/wrangler/src/__tests__/dev.test.ts

+18-64
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ describe.sequential("wrangler dev", () => {
142142
msw.resetHandlers();
143143
spy.mockClear();
144144
setSpy.mockClear();
145+
logger.resetLoggerLevel();
145146
});
146147

147148
async function runWranglerUntilConfig(
@@ -1211,7 +1212,7 @@ describe.sequential("wrangler dev", () => {
12111212
);
12121213
expect(std.out).toMatchInlineSnapshot(`
12131214
"Your Worker and resources are simulated locally via Miniflare. For more information, see: https://developers.cloudflare.com/workers/testing/local-development.
1214-
1215+
12151216
Your worker has access to the following bindings:
12161217
- Durable Objects:
12171218
- NAME_1: CLASS_1
@@ -1304,7 +1305,7 @@ describe.sequential("wrangler dev", () => {
13041305
expect(std.out).toMatchInlineSnapshot(`
13051306
"Using vars defined in .dev.vars
13061307
Your Worker and resources are simulated locally via Miniflare. For more information, see: https://developers.cloudflare.com/workers/testing/local-development.
1307-
1308+
13081309
Your worker has access to the following bindings:
13091310
- Vars:
13101311
- VAR_1: \\"(hidden)\\"
@@ -1340,7 +1341,7 @@ describe.sequential("wrangler dev", () => {
13401341
expect(std.out).toMatchInlineSnapshot(`
13411342
"Using vars defined in .dev.vars.custom
13421343
Your Worker and resources are simulated locally via Miniflare. For more information, see: https://developers.cloudflare.com/workers/testing/local-development.
1343-
1344+
13441345
Your worker has access to the following bindings:
13451346
- Vars:
13461347
- CUSTOM_VAR: \\"(hidden)\\"
@@ -1356,64 +1357,6 @@ describe.sequential("wrangler dev", () => {
13561357
).rejects.toThrowErrorMatchingInlineSnapshot(
13571358
`[Error: Not enough arguments following: site]`
13581359
);
1359-
1360-
expect(std).toMatchInlineSnapshot(`
1361-
Object {
1362-
"debug": "",
1363-
"err": "X [ERROR] Not enough arguments following: site
1364-
1365-
",
1366-
"info": "",
1367-
"out": "
1368-
wrangler dev [script]
1369-
1370-
👂 Start a local server for developing your Worker
1371-
1372-
POSITIONALS
1373-
script The path to an entry point for your Worker [string]
1374-
1375-
GLOBAL FLAGS
1376-
-c, --config Path to Wrangler configuration file [string]
1377-
-e, --env Environment to use for operations, and for selecting .env and .dev.vars files [string]
1378-
-h, --help Show help [boolean]
1379-
-v, --version Show version number [boolean]
1380-
1381-
OPTIONS
1382-
--name Name of the Worker [string]
1383-
--compatibility-date Date to use for compatibility checks [string]
1384-
--compatibility-flags, --compatibility-flag Flags to use for compatibility checks [array]
1385-
--latest Use the latest version of the Workers runtime [boolean] [default: true]
1386-
--assets Static assets to be served. Replaces Workers Sites. [string]
1387-
--no-bundle Skip internal build steps and directly deploy script [boolean] [default: false]
1388-
--ip IP address to listen on [string]
1389-
--port Port to listen on [number]
1390-
--inspector-port Port for devtools to connect to [number]
1391-
--routes, --route Routes to upload [array]
1392-
--host Host to forward requests to, defaults to the zone of project [string]
1393-
--local-protocol Protocol to listen to requests on, defaults to http. [choices: \\"http\\", \\"https\\"]
1394-
--https-key-path Path to a custom certificate key [string]
1395-
--https-cert-path Path to a custom certificate [string]
1396-
--local-upstream Host to act as origin in local mode, defaults to dev.host or route [string]
1397-
--upstream-protocol Protocol to forward requests to host on, defaults to https. [choices: \\"http\\", \\"https\\"]
1398-
--var A key-value pair to be injected into the script as a variable [array]
1399-
--define A key-value pair to be substituted in the script [array]
1400-
--alias A module pair to be substituted in the script [array]
1401-
--jsx-factory The function that is called for each JSX element [string]
1402-
--jsx-fragment The function that is called for each JSX fragment [string]
1403-
--tsconfig Path to a custom tsconfig.json file [string]
1404-
-r, --remote Run on the global Cloudflare network with access to production resources [boolean] [default: false]
1405-
--minify Minify the script [boolean]
1406-
--node-compat Enable Node.js compatibility [boolean]
1407-
--persist-to Specify directory to use for local persistence (defaults to .wrangler/state) [string]
1408-
--live-reload Auto reload HTML pages when change is detected in local mode [boolean]
1409-
--test-scheduled Test scheduled events by visiting /__scheduled in browser [boolean] [default: false]
1410-
--log-level Specify logging level [choices: \\"debug\\", \\"info\\", \\"log\\", \\"warn\\", \\"error\\", \\"none\\"] [default: \\"log\\"]
1411-
--show-interactive-dev-session Show interactive dev session (defaults to true if the terminal supports interactivity) [boolean]
1412-
--experimental-vectorize-bind-to-prod Bind to production Vectorize indexes in local development mode [boolean] [default: false]
1413-
--experimental-images-local-mode Use a local lower-fidelity implementation of the Images binding [boolean] [default: false]",
1414-
"warn": "",
1415-
}
1416-
`);
14171360
});
14181361

14191362
it("should error if --legacy-assets and --site are used together", async () => {
@@ -1831,6 +1774,17 @@ describe.sequential("wrangler dev", () => {
18311774
"
18321775
`);
18331776
});
1777+
1778+
it("should also set log level using WRANGLER_LOG'", async () => {
1779+
fs.writeFileSync("index.js", `export default {};`);
1780+
vi.stubEnv("WRANGLER_LOG", "none");
1781+
await runWranglerUntilConfig("dev index.js --inspect");
1782+
expect(std.warn).toMatchInlineSnapshot(`""`);
1783+
1784+
vi.stubEnv("WRANGLER_LOG", "debug");
1785+
await runWranglerUntilConfig("dev index.js");
1786+
expect(std.debug).toContain(".env file not found at");
1787+
});
18341788
});
18351789

18361790
describe("--show-interactive-dev-session", () => {
@@ -1862,7 +1816,7 @@ describe.sequential("wrangler dev", () => {
18621816
await runWranglerUntilConfig("dev index.js");
18631817
expect(std.out).toMatchInlineSnapshot(`
18641818
"Your Worker and resources are simulated locally via Miniflare. For more information, see: https://developers.cloudflare.com/workers/testing/local-development.
1865-
1819+
18661820
Your worker has access to the following bindings:
18671821
- Services:
18681822
- WorkerA: A [not connected]
@@ -1885,7 +1839,7 @@ describe.sequential("wrangler dev", () => {
18851839
await runWranglerUntilConfig("dev index.js");
18861840
expect(std.out).toMatchInlineSnapshot(`
18871841
"Your Worker and resources are simulated locally via Miniflare. For more information, see: https://developers.cloudflare.com/workers/testing/local-development.
1888-
1842+
18891843
Your worker has access to the following bindings:
18901844
- Services:
18911845
- WorkerA: A [not connected]
@@ -1914,7 +1868,7 @@ describe.sequential("wrangler dev", () => {
19141868
expect(std.out).toMatchInlineSnapshot(`
19151869
"Using vars defined in .dev.vars
19161870
Your Worker and resources are simulated locally via Miniflare. For more information, see: https://developers.cloudflare.com/workers/testing/local-development.
1917-
1871+
19181872
Your worker has access to the following bindings:
19191873
- Vars:
19201874
- variable: 123

‎packages/wrangler/src/__tests__/metrics.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ describe("metrics", () => {
5656
afterEach(() => {
5757
vi.unstubAllEnvs();
5858
isCISpy.mockClear();
59+
logger.resetLoggerLevel();
5960
});
6061

6162
describe("getMetricsDispatcher()", () => {

‎packages/wrangler/src/__tests__/pages/pages-build-env.test.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ import { writeWranglerConfig } from "../helpers/write-wrangler-config";
1414
describe("pages build env", () => {
1515
const std = mockConsoleMethods();
1616
runInTempDir();
17-
const originalLoggerLevel = logger.loggerLevel;
1817

1918
afterEach(() => {
20-
logger.loggerLevel = originalLoggerLevel;
19+
logger.resetLoggerLevel();
2120
});
2221
beforeEach(() => {
2322
vi.stubEnv("PAGES_ENVIRONMENT", "production");

‎packages/wrangler/src/dev.ts

-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ import type {
5050
} from "./deployment-bundle/worker";
5151
import type { WorkerRegistry } from "./dev-registry";
5252
import type { CfAccount } from "./dev/create-worker-preview";
53-
import type { LoggerLevel } from "./logger";
5453
import type { EnablePagesAssetsServiceBindingOptions } from "./miniflare-cli/types";
5554
import type { watch } from "chokidar";
5655
import type { Json } from "miniflare";
@@ -310,8 +309,6 @@ export const dev = createCommand({
310309
"log-level": {
311310
choices: ["debug", "info", "log", "warn", "error", "none"] as const,
312311
describe: "Specify logging level",
313-
// Yargs requires this to type log-level properly
314-
default: "log" as LoggerLevel,
315312
},
316313
"show-interactive-dev-session": {
317314
describe:

‎packages/wrangler/src/logger.ts

+4
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ export class Logger {
6565
this.overrideLoggerLevel = val;
6666
}
6767

68+
resetLoggerLevel() {
69+
this.overrideLoggerLevel = undefined;
70+
}
71+
6872
columns = process.stdout.columns;
6973

7074
debug = (...args: unknown[]) => this.doLog("debug", args);

0 commit comments

Comments
 (0)
Please sign in to comment.