Skip to content

Commit 122bd0b

Browse files
authored
fix: cleaner startup logs (#309)
* fix: cleaner startup logs * fix linting issue
1 parent 60fe967 commit 122bd0b

3 files changed

Lines changed: 21 additions & 7 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ Installs Devtron into the Electron app. Refer to [Configuring an Electron App to
5555

5656
#### `Options`
5757

58-
| Option | Type | Default | Description |
59-
| ---------- | -------------------------------------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
60-
| `logLevel` | `'debug' \| 'info' \| 'warn' \| 'error' \| 'none'` | `'debug'` | Sets the minimum log level for the logger. Messages below this level are ignored. <br><br> **Levels:** <br>• `debug` — logs: debug, info, warn, error <br>• `info` — logs: info, warn, error <br>• `warn` — logs: warn, error <br>• `error` — logs: error only <br>• `none` — disables all logging |
58+
| Option | Type | Default | Description |
59+
| ---------- | -------------------------------------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
60+
| `logLevel` | `'debug' \| 'info' \| 'warn' \| 'error' \| 'none'` | `'warn'` | Sets the minimum log level for the logger. Messages below this level are ignored. <br><br> **Levels:** <br>• `debug` — logs: debug, info, warn, error <br>• `info` — logs: info, warn, error <br>• `warn` — logs: warn, error <br>• `error` — logs: error only <br>• `none` — disables all logging |
6161

6262
Examples:
6363

src/index.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ let isInstalled = false;
2727
let isInstalledToDefaultSession = false;
2828
let devtronSW: Electron.ServiceWorkerMain;
2929

30+
/**
31+
* Count the number of IPC calls that were made before the service worker was ready.
32+
* Used for logging purposes.
33+
*/
34+
let untrackedIpcCalls = 0;
35+
3036
const isPayloadWithUuid = (payload: any[]): boolean => {
3137
// If the first argument is an object with __uuid__devtron then it is a custom payload
3238
return (
@@ -67,7 +73,10 @@ function trackIpcEvent({
6773
if (excludedIpcChannels.includes(channel)) return;
6874

6975
if (!devtronSW) {
70-
logger.warn('The service-worker for Devtron is not registered yet. Cannot track IPC event.');
76+
logger.info(
77+
`The service worker for Devtron is not registered yet. Cannot track ${direction} IPC event for channel ${channel}.`,
78+
);
79+
untrackedIpcCalls++;
7180
return;
7281
}
7382

@@ -415,7 +424,12 @@ async function install(options: InstallOptions = {}) {
415424
const extensionPath = path.resolve(serviceWorkerPreloadPath, '..', '..', 'extension');
416425
devtron = await ses.extensions.loadExtension(extensionPath, { allowFileAccess: true });
417426
await startServiceWorker(ses, devtron);
418-
logger.info('Devtron loaded successfully');
427+
if (untrackedIpcCalls > 0) {
428+
logger.warn(
429+
`${untrackedIpcCalls} untracked IPC events were dispatched before the service worker was ready.`,
430+
);
431+
}
432+
logger.info('Devtron service worker loaded successfully');
419433
} catch (error) {
420434
logger.error('Failed to load Devtron:', error);
421435
}
@@ -440,7 +454,7 @@ async function getEvents(): Promise<IpcEventDataIndexed[]> {
440454
}
441455

442456
if (!devtronSW) {
443-
logger.warn('Devtron service-worker is not registered yet. Cannot get IPC events.');
457+
logger.warn('Devtron service worker is not registered yet. Cannot get IPC events.');
444458
return [];
445459
}
446460

src/utils/Logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { LogLevelString } from '../types/shared';
22
import { LogLevel } from '../types/shared';
33

44
class Logger {
5-
private currentLogLevel = LogLevel.debug;
5+
private currentLogLevel = LogLevel.warn;
66

77
setLogLevel(level: LogLevelString) {
88
if (LogLevel[level] === undefined) {

0 commit comments

Comments
 (0)