Skip to content

Commit eeb07e7

Browse files
committed
Add verbose flag
1 parent 227d64f commit eeb07e7

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

core/loadConfig.js

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import yargs from 'yargs';
1010
/* eslint-disable-next-line n/file-extension-in-import */
1111
import { hideBin } from 'yargs/helpers';
1212
import _ from 'underscore';
13+
import chalk from 'chalk';
1314

1415
import { console } from '../lib/Cluster.js';
1516
import SaplingError from '../lib/SaplingError.js';
@@ -157,6 +158,8 @@ export default async function loadConfig(next) {
157158
/* Digest config */
158159
this.config = await digest.call(this);
159160
console.log('CONFIG', this.config);
161+
console.logAlways(this.config.production ? chalk.green('Production mode is ON') : chalk.yellow('Production mode is OFF'));
162+
console.logAlways(this.config.strict ? chalk.green('Strict mode is ON') : chalk.yellow('Strict mode is OFF'));
160163

161164
/* Set the app name */
162165
this.name = this.config.name;

lib/Cluster.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,17 @@ const originalConsole = console;
2121
/* Prefixing native console methods with worker ID */
2222
const prefixedConsole = {
2323
log(...args) {
24+
if (process.env.NODE_ENV !== 'test' && Cluster.verbose) {
25+
originalConsole.log(Cluster.workerID() + ' '.repeat(currentIndent), ...args);
26+
}
27+
},
28+
logAlways(...args) {
2429
if (process.env.NODE_ENV !== 'test') {
2530
originalConsole.log(Cluster.workerID() + ' '.repeat(currentIndent), ...args);
2631
}
2732
},
2833
warn(...args) {
29-
if (process.env.NODE_ENV !== 'test') {
34+
if (process.env.NODE_ENV !== 'test' && Cluster.verbose) {
3035
originalConsole.warn(Cluster.workerID() + ' '.repeat(currentIndent), ...args);
3136
}
3237
},
@@ -36,13 +41,13 @@ const prefixedConsole = {
3641
}
3742
},
3843
group(...args) {
39-
if (process.env.NODE_ENV !== 'test') {
44+
if (process.env.NODE_ENV !== 'test' && Cluster.verbose) {
4045
originalConsole.log(Cluster.workerID(), chalk.blue.bold(...args));
4146
currentIndent += indentAmount;
4247
}
4348
},
4449
groupEnd() {
45-
if (process.env.NODE_ENV !== 'test') {
50+
if (process.env.NODE_ENV !== 'test' && Cluster.verbose) {
4651
currentIndent -= indentAmount;
4752
}
4853
},
@@ -52,6 +57,8 @@ const prefixedConsole = {
5257
const Cluster = {
5358
console: prefixedConsole,
5459

60+
verbose: true,
61+
5562
/* Create an access log line */
5663
logger(tokens, request, response) {
5764
if (process.env.NODE_ENV !== 'test') {

0 commit comments

Comments
 (0)