From 1abca7619d62d5d01ed096c179940d41f198779c Mon Sep 17 00:00:00 2001
From: Michael Clark <5285928+MikesGlitch@users.noreply.github.com>
Date: Thu, 8 Aug 2024 12:45:57 -0700
Subject: [PATCH]  :electron:  Making Electron server logs visible in devtools
 (#3219)

* add electron logging to main browser process console

* add logging

* removing old way

* release notes
---
 packages/desktop-electron/index.ts                 | 14 +++++++++++++-
 .../src/platform/exceptions/index.electron.ts      |  2 +-
 upcoming-release-notes/3219.md                     |  6 ++++++
 3 files changed, 20 insertions(+), 2 deletions(-)
 create mode 100644 upcoming-release-notes/3219.md

diff --git a/packages/desktop-electron/index.ts b/packages/desktop-electron/index.ts
index c7d9df812..d5767d200 100644
--- a/packages/desktop-electron/index.ts
+++ b/packages/desktop-electron/index.ts
@@ -60,9 +60,21 @@ function createBackgroundProcess() {
   serverProcess = utilityProcess.fork(
     __dirname + '/server.js',
     ['--subprocess', app.getVersion()],
-    isDev ? { execArgv: ['--inspect'] } : undefined,
+    isDev ? { execArgv: ['--inspect'], stdio: 'pipe' } : { stdio: 'pipe' },
   );
 
+  serverProcess.stdout.on('data', (chunk: Buffer) => {
+    // Send the Server console.log messages to the main browser window
+    clientWin?.webContents.executeJavaScript(`
+      console.info('Server Log:', ${JSON.stringify(chunk.toString('utf8'))})`);
+  });
+
+  serverProcess.stderr.on('data', (chunk: Buffer) => {
+    // Send the Server console.error messages out to the main browser window
+    clientWin?.webContents.executeJavaScript(`
+      console.error('Server Log:', ${JSON.stringify(chunk.toString('utf8'))})`);
+  });
+
   serverProcess.on('message', msg => {
     switch (msg.type) {
       case 'captureEvent':
diff --git a/packages/loot-core/src/platform/exceptions/index.electron.ts b/packages/loot-core/src/platform/exceptions/index.electron.ts
index 95adc8295..caeb92917 100644
--- a/packages/loot-core/src/platform/exceptions/index.electron.ts
+++ b/packages/loot-core/src/platform/exceptions/index.electron.ts
@@ -1,7 +1,7 @@
 import type * as T from '.';
 
 export const captureException: T.CaptureException = function (exc) {
-  console.log('[Exception]', exc);
+  console.error('[Exception]', exc);
 };
 
 export const captureBreadcrumb: T.CaptureBreadcrumb = function () {};
diff --git a/upcoming-release-notes/3219.md b/upcoming-release-notes/3219.md
new file mode 100644
index 000000000..4c73e3a5f
--- /dev/null
+++ b/upcoming-release-notes/3219.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [MikesGlitch]
+---
+
+Makinig Server logs visible in devtools on Electron
-- 
GitLab