Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix(logging): Suppress packaged Windows console output (#1719)

Chad Piha30dedcf31f3b
diff --git a/CLAUDE.md b/CLAUDE.md
index 143d6138c..f39b47650 100644
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@ -465,6 +465,11 @@ Enable with `--log-level=debug` or `OPENWHISPR_LOG_LEVEL=debug` (can be set in `
- Audio level analysis
- Complete reasoning pipeline debugging with stage-by-stage logging
+Packaged Windows builds keep logger output off stdout/stderr by default. Launch with
+`--console-logs` to opt into terminal output independently of the configured log level.
+Default INFO entries are not persisted in this mode; enabling debug logging retains them
+in the existing log file without enabling terminal output.
+
### 12. Windows Push-to-Talk
Native Windows support for true push-to-talk functionality using low-level keyboard hooks:
diff --git a/src/helpers/debugLogger.js b/src/helpers/debugLogger.js
index 1cb7b4303..4dc221c2f 100644
--- a/src/helpers/debugLogger.js
+++ b/src/helpers/debugLogger.js
@@ -31,6 +31,8 @@ const readArgLogLevel = () => {
return null;
};
+const hasConsoleLogOptIn = () => (process.argv || []).includes("--console-logs");
+
class DebugLogger {
constructor() {
this.logLevel = this.resolveLogLevel();
@@ -40,6 +42,7 @@ class DebugLogger {
this.logStream = null;
this.fileLoggingEnabled = false;
this.fileLoggingPending = this.debugMode; // Track if we need to initialize file logging later
+ this.consoleLoggingEnabled = this.resolveConsoleLogging();
// IMPORTANT: Do NOT call initializeFileLogging() here!
// It uses app.getPath() which is unsafe before app.whenReady().
@@ -110,6 +113,11 @@ class DebugLogger {
return "info";
}
+ resolveConsoleLogging() {
+ // Packaged Windows apps can inherit the launching shell's standard handles.
+ return process.platform !== "win32" || !app.isPackaged || hasConsoleLogOptIn();
+ }
+
refreshLogLevel() {
const nextLevel = this.resolveLogLevel();
if (nextLevel === this.logLevel) return;
@@ -191,18 +199,20 @@ class DebugLogger {
const metaText = this.formatMeta(meta);
const logLine = metaText ? `${baseLine} ${metaText}\n` : `${baseLine}\n`;
- const consoleFn =
- normalized === "error" || normalized === "fatal"
- ? console.error
- : normalized === "warn"
- ? console.warn
- : console.log;
-
- if (meta !== undefined) {
- // Pass the prefix as a %s arg, not as a format string. See CodeQL js/tainted-format-string.
- consoleFn("%s", `${levelTag}${scopeTag}${sourceTag} ${message}`, meta);
- } else {
- consoleFn(`${levelTag}${scopeTag}${sourceTag} ${message}`);
+ if (this.consoleLoggingEnabled) {
+ const consoleFn =
+ normalized === "error" || normalized === "fatal"
+ ? console.error
+ : normalized === "warn"
+ ? console.warn
+ : console.log;
+
+ if (meta !== undefined) {
+ // Pass the prefix as a %s arg, not as a format string. See CodeQL js/tainted-format-string.
+ consoleFn("%s", `${levelTag}${scopeTag}${sourceTag} ${message}`, meta);
+ } else {
+ consoleFn(`${levelTag}${scopeTag}${sourceTag} ${message}`);
+ }
}
if (this.logStream) {
diff --git a/src/helpers/dragManager.js b/src/helpers/dragManager.js
index ae860b013..1fd462356 100644
--- a/src/helpers/dragManager.js
+++ b/src/helpers/dragManager.js
@@ -1,5 +1,6 @@
const { screen } = require("electron");
const { WindowPositionUtil } = require("./windowConfig");
+const debugLogger = require("./debugLogger");
class DragManager {
constructor() {
@@ -34,7 +35,7 @@ class DragManager {
// Start tracking mouse movements
this.setupMouseTracking();
- console.log("🖱️ Window drag started");
+ debugLogger.info("Window drag started", undefined, "window-drag");
return { success: true };
} catch (error) {
console.error("Failed to start window drag:", error);
@@ -47,7 +48,7 @@ class DragManager {
try {
this.isDragging = false;
this.stopMouseTracking();
- console.log("🖱️ Window drag stopped");
+ debugLogger.info("Window drag stopped", undefined, "window-drag");
return { success: true };
} catch (error) {
console.error("Failed to stop window drag:", error);
diff --git a/test/helpers/debugLoggerConsolePolicy.test.js b/test/helpers/debugLoggerConsolePolicy.test.js
new file mode 100644
index 000000000..5f2b307c9
--- /dev/null
+++ b/test/helpers/debugLoggerConsolePolicy.test.js
@@ -0,0 +1,256 @@
+const test = require("node:test");
+const assert = require("node:assert/strict");
+const fs = require("node:fs");
+const os = require("node:os");
+const path = require("node:path");
+const Module = require("node:module");
+
+const loggerPath = require.resolve("../../src/helpers/debugLogger.js");
+const dragManagerPath = require.resolve("../../src/helpers/dragManager.js");
+const originalLoad = Module._load;
+const originalPlatform = Object.getOwnPropertyDescriptor(process, "platform");
+
+function withRuntime({ platform, argv = [], env = {}, electron }, loadModule) {
+ const previousArgv = process.argv;
+ const previousEnvironment = {
+ LOG_LEVEL: process.env.LOG_LEVEL,
+ NODE_ENV: process.env.NODE_ENV,
+ OPENWHISPR_LOG_LEVEL: process.env.OPENWHISPR_LOG_LEVEL,
+ };
+
+ Object.defineProperty(process, "platform", { value: platform, configurable: true });
+ process.argv = ["node", "main.js", ...argv];
+ delete process.env.LOG_LEVEL;
+ delete process.env.NODE_ENV;
+ delete process.env.OPENWHISPR_LOG_LEVEL;
+ Object.assign(process.env, env);
+
+ Module._load = function loadWithElectronMock(request, parent, isMain) {
+ if (request === "electron") return electron;
+ return originalLoad.call(this, request, parent, isMain);
+ };
+
+ try {
+ return loadModule();
+ } finally {
+ Module._load = originalLoad;
+ Object.defineProperty(process, "platform", originalPlatform);
+ process.argv = previousArgv;
+ delete process.env.LOG_LEVEL;
+ delete process.env.NODE_ENV;
+ delete process.env.OPENWHISPR_LOG_LEVEL;
+ for (const [name, value] of Object.entries(previousEnvironment)) {
+ if (value !== undefined) process.env[name] = value;
+ }
+ }
+}
+
+function loadLogger({
+ platform,
+ isPackaged,
+ argv,
+ env,
+ isReady = false,
+ userDataPath = os.tmpdir(),
+}) {
+ delete require.cache[loggerPath];
+ return withRuntime(
+ {
+ platform,
+ argv,
+ env,
+ electron: {
+ app: {
+ getAppPath: () => "/openwhispr",
+ getPath: () => userDataPath,
+ isPackaged,
+ isReady: () => isReady,
+ },
+ },
+ },
+ () => require(loggerPath)
+ );
+}
+
+async function captureConsole(run) {
+ const calls = [];
+ const originalConsole = {
+ error: console.error,
+ log: console.log,
+ warn: console.warn,
+ };
+
+ console.error = (...args) => calls.push(["error", ...args]);
+ console.log = (...args) => calls.push(["log", ...args]);
+ console.warn = (...args) => calls.push(["warn", ...args]);
+ try {
+ await run();
+ } finally {
+ Object.assign(console, originalConsole);
+ }
+ return calls;
+}
+
+async function closeLogStream(logger) {
+ if (!logger.logStream) return;
+ const logStream = logger.logStream;
+ logger.logStream = null;
+ await new Promise((resolve, reject) => {
+ logStream.once("error", reject);
+ logStream.end(resolve);
+ });
+}
+
+test(
+ "packaged Windows suppresses main and renderer console logging at the default level",
+ async () => {
+ const logger = loadLogger({ platform: "win32", isPackaged: true });
+
+ const calls = await captureConsole(() => {
+ logger.info("Recording started", { microphone: "Default" }, "audio");
+ logger.warn("Recording warning");
+ logger.error("Recording failure");
+ logger.logEntry({
+ level: "info",
+ message: "Pipeline timing",
+ meta: { roundTripDurationMs: 42 },
+ scope: "performance",
+ source: "renderer",
+ });
+ });
+
+ assert.deepEqual(calls, []);
+ assert.equal(logger.getLogPath(), null, "default INFO logging remains non-persistent");
+ }
+);
+
+test("log-level settings never opt a packaged Windows build into console logging", async (t) => {
+ const cases = [
+ { name: "--log-level", argv: ["--log-level=debug"] },
+ {
+ name: "OPENWHISPR_LOG_LEVEL=debug",
+ env: { OPENWHISPR_LOG_LEVEL: "debug" },
+ },
+ {
+ name: "OPENWHISPR_LOG_LEVEL=info",
+ env: { OPENWHISPR_LOG_LEVEL: "info" },
+ },
+ { name: "LOG_LEVEL", env: { LOG_LEVEL: "debug" } },
+ ];
+
+ for (const testCase of cases) {
+ await t.test(testCase.name, async () => {
+ const logger = loadLogger({
+ platform: "win32",
+ isPackaged: true,
+ argv: testCase.argv,
+ env: testCase.env,
+ });
+
+ const calls = await captureConsole(() => logger.info("Configured log level"));
+
+ assert.deepEqual(calls, []);
+ });
+ }
+});
+
+test("--console-logs explicitly enables console logging in packaged Windows", async () => {
+ const logger = loadLogger({
+ platform: "win32",
+ isPackaged: true,
+ argv: ["--console-logs"],
+ });
+
+ const calls = await captureConsole(() => logger.info("Console diagnostics enabled"));
+
+ assert.deepEqual(calls, [["log", "[INFO] Console diagnostics enabled"]]);
+});
+
+test("development and non-Windows packaged builds preserve console logging", async (t) => {
+ const cases = [
+ { name: "Windows development", platform: "win32", isPackaged: false },
+ { name: "packaged macOS", platform: "darwin", isPackaged: true },
+ { name: "packaged Linux", platform: "linux", isPackaged: true },
+ ];
+
+ for (const testCase of cases) {
+ await t.test(testCase.name, async () => {
+ const logger = loadLogger(testCase);
+
+ const calls = await captureConsole(() => logger.info("Existing console behavior"));
+
+ assert.deepEqual(calls, [["log", "[INFO] Existing console behavior"]]);
+ });
+ }
+});
+
+test(
+ "packaged Windows retains debug logs in the file sink while suppressing the console",
+ async () => {
+ const userDataPath = fs.mkdtempSync(path.join(os.tmpdir(), "openwhispr-debug-logger-"));
+ const logger = loadLogger({
+ platform: "win32",
+ isPackaged: true,
+ env: { OPENWHISPR_LOG_LEVEL: "debug" },
+ isReady: true,
+ userDataPath,
+ });
+
+ try {
+ const calls = await captureConsole(() => {
+ logger.logEntry({
+ level: "info",
+ message: "Pipeline timing",
+ scope: "performance",
+ source: "renderer",
+ });
+ });
+ const logPath = logger.getLogPath();
+ await closeLogStream(logger);
+
+ assert.deepEqual(calls, []);
+ assert.ok(logPath);
+ assert.match(
+ fs.readFileSync(logPath, "utf8"),
+ /\[INFO\]\[performance\]\[renderer\] Pipeline timing/
+ );
+ } finally {
+ await closeLogStream(logger);
+ fs.rmSync(userDataPath, { recursive: true, force: true });
+ }
+ }
+);
+
+test("routine window-drag activity obeys the packaged Windows console policy", async () => {
+ delete require.cache[loggerPath];
+ delete require.cache[dragManagerPath];
+ const DragManager = withRuntime(
+ {
+ platform: "win32",
+ electron: {
+ app: {
+ getAppPath: () => "/openwhispr",
+ getPath: () => os.tmpdir(),
+ isPackaged: true,
+ isReady: () => false,
+ },
+ screen: {
+ getCursorScreenPoint: () => ({ x: 120, y: 80 }),
+ },
+ },
+ },
+ () => require(dragManagerPath)
+ );
+ const dragManager = new DragManager();
+ dragManager.setTargetWindow({
+ getPosition: () => [100, 50],
+ isDestroyed: () => false,
+ });
+
+ const calls = await captureConsole(async () => {
+ assert.deepEqual(await dragManager.startWindowDrag(), { success: true });
+ assert.deepEqual(await dragManager.stopWindowDrag(), { success: true });
+ });
+
+ assert.deepEqual(calls, []);
+});