Skip to content

Commit 734792a

Browse files
Fix: make sure that remote proxy sessions's logs can be silenced when the wrangler log level is set to "none" (#12498)
1 parent 58ae627 commit 734792a

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

.changeset/every-dolls-type.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
Fix: make sure that remote proxy sessions's logs can be silenced when the wrangler log level is set to "none"

packages/wrangler/src/api/remoteBindings/start-remote-proxy-session.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import remoteBindingsWorkerPath from "worker:remoteBindings/ProxyServerWorker";
55
import { logger } from "../../logger";
66
import { getBasePath } from "../../paths";
77
import { startWorker } from "../startDevWorker";
8+
import type { LoggerLevel } from "../../logger";
89
import type { StartDevWorkerInput, Worker } from "../startDevWorker";
910
import type { Config } from "@cloudflare/workers-utils";
1011
import type { RemoteProxyConnectionString } from "miniflare";
@@ -45,11 +46,7 @@ export async function startRemoteProxySession(
4546
port: await getPort(),
4647
},
4748
inspector: false,
48-
logLevel:
49-
// If the logger has a logLevel of "debug" it means that the user is likely trying to debug some issue,
50-
// so we should respect that here as well for the remote proxy session. In any other case, to avoid noisy
51-
// logs, we just simply fall back to "error"
52-
logger.loggerLevel === "debug" ? "debug" : "error",
49+
logLevel: getStartWorkerLogLevel(logger.loggerLevel),
5350
},
5451
bindings: rawBindings,
5552
}).catch((startWorkerError) => {
@@ -114,3 +111,27 @@ export type RemoteProxySession = Pick<Worker, "ready" | "dispose"> & {
114111
updateBindings: (bindings: StartDevWorkerInput["bindings"]) => Promise<void>;
115112
remoteProxyConnectionString: RemoteProxyConnectionString;
116113
};
114+
115+
/**
116+
* Gets the log level to use for the remote worker.
117+
*
118+
* @param wranglerLogLevel The log level set for the Wrangler process.
119+
* @returns The log level to use for the remove worker.
120+
*/
121+
function getStartWorkerLogLevel(wranglerLogLevel: LoggerLevel): LoggerLevel {
122+
switch (wranglerLogLevel) {
123+
case "debug":
124+
// If the `logLevel` is "debug" it means that the user is likely trying to debug some issue,
125+
// so we should respect that here as well for the remote proxy session.
126+
return "debug";
127+
128+
case "none":
129+
// If the `logLevel` is "none" it means that the user is trying to silence all output,
130+
// so we should respect that here as well for the remote proxy session.
131+
return "none";
132+
133+
default:
134+
// In any other case we want to default to "error" to avoid noisy logs
135+
return "error";
136+
}
137+
}

0 commit comments

Comments
 (0)