Skip to content

Commit

Permalink
Enable debug in development mode by default
Browse files Browse the repository at this point in the history
  • Loading branch information
StealthCoder1109 committed Sep 26, 2023
1 parent cbd21d0 commit cdf2e09
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
],
"scripts": {
"dev": "evershop dev",
"dev:debug": "evershop dev --debug",
"setup": "evershop install",
"build": "evershop build",
"start": "evershop start",
Expand Down
68 changes: 35 additions & 33 deletions packages/evershop/src/lib/log/debuger.js
Original file line number Diff line number Diff line change
@@ -1,43 +1,45 @@
const { green, red, blue, yellow, white } = require('kleur');
const isDevelopmentMode = require('../util/isDevelopmentMode');

// Define logger function
function debug(level, message) {
if (!process.argv.includes('--debug')) {
return; // Do not output message to console or file
}
let logMessage = ``;
let textMessage = `${message}`;
// If message is an exception object, include the stack trace
if (message instanceof Error) {
textMessage = `${message.message}\n${message.stack}`;
}
// Switch color based on level
switch (level) {
case 'critical':
logMessage += red(`[debug] ❌ ${textMessage}`);
break;
case 'warning':
logMessage += yellow(`[debug] ⚠️ ${textMessage}`);
break;
case 'info':
logMessage += blue(`[debug] ℹ️ ${textMessage}`);
break;
case 'success':
logMessage += green(`[debug] ✅ ${textMessage}`);
break;
default:
logMessage += white(`[debug] - ${textMessage}`);
break;
}
if (isDevelopmentMode() || process.argv.includes('--debug')) {
let logMessage = ``;
let textMessage = `${message}`;
// If message is an exception object, include the stack trace
if (message instanceof Error) {
textMessage = `${message.message}\n${message.stack}`;
}
// Switch color based on level
switch (level) {
case 'critical':
logMessage += red(`[debug] ❌ ${textMessage}`);
break;
case 'warning':
logMessage += yellow(`[debug] ⚠️ ${textMessage}`);
break;
case 'info':
logMessage += blue(`[debug] ℹ️ ${textMessage}`);
break;
case 'success':
logMessage += green(`[debug] ✅ ${textMessage}`);
break;
default:
logMessage += white(`[debug] - ${textMessage}`);
break;
}

// If message is added to a group, store it in the group
if (this.group && Array.isArray(this.group.messages)) {
this.group.messages.push(logMessage);
// If message is added to a group, store it in the group
if (this.group && Array.isArray(this.group.messages)) {
this.group.messages.push(logMessage);
return; // Do not output message to console or file
}

// eslint-disable-next-line no-console
console.log(logMessage);
} else {
return; // Do not output message to console or file
}

// eslint-disable-next-line no-console
console.log(logMessage);
}

function error(e) {
Expand Down

0 comments on commit cdf2e09

Please sign in to comment.