Skip to content

Commit

Permalink
Add color to node console logs (#210)
Browse files Browse the repository at this point in the history
- make it clearer and easier to see warnings and errors in the node console.
  • Loading branch information
irahopkinson authored and lyonsil committed Jun 13, 2023
1 parent 67a44cc commit 24fd789
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
20 changes: 4 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"@emotion/styled": "^11.10.6",
"@mui/material": "^5.11.12",
"async-mutex": "^0.4.0",
"chalk": "^4.1.2",
"electron-debug": "^3.2.0",
"electron-log": "^5.0.0-beta.19",
"electron-updater": "^5.3.0",
Expand Down Expand Up @@ -138,7 +139,6 @@
"@typescript-eslint/eslint-plugin": "^5.55.0",
"@typescript-eslint/parser": "^5.55.0",
"browserslist-config-erb": "^0.0.3",
"chalk": "^4.1.2",
"concurrently": "^7.6.0",
"core-js": "^3.29.1",
"cross-env": "^7.0.3",
Expand Down
22 changes: 22 additions & 0 deletions src/shared/services/logger.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import chalk from 'chalk';
import log, { LogLevel } from 'electron-log';
import { getProcessType, isClient, isRenderer } from '@shared/utils/internal-util';

Expand Down Expand Up @@ -50,6 +51,27 @@ if (isClient()) {
} else {
log.initialize();
log.transports.console.level = level;
log.transports.console.format = '{h}:{i}:{s} {text}';
log.transports.console.writeFn = ({ message: msg }) => {
const message = `${msg.data}`;

/* eslint-disable no-console */
switch (msg.level) {
case 'info':
console.log(message);
break;
case 'warn':
console.log(chalk.yellow(message));
break;
case 'error':
console.log(chalk.red(message));
break;
default:
console.log(message);
break;
}
/* eslint-enable */
};
log.transports.file.level = level;
}

Expand Down

0 comments on commit 24fd789

Please sign in to comment.