Skip to content

Commit 827f550

Browse files
committedJul 24, 2022
Load verbosity from config
1 parent eeb07e7 commit 827f550

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed
 

‎core/loadConfig.js

+5
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ export async function digest() {
157157
export default async function loadConfig(next) {
158158
/* Digest config */
159159
this.config = await digest.call(this);
160+
161+
/* Set logging verbosity */
162+
process.env.VERBOSE_LOGGING = ('verbose' in this.config) ? this.config.verbose : true;
163+
164+
/* Log config */
160165
console.log('CONFIG', this.config);
161166
console.logAlways(this.config.production ? chalk.green('Production mode is ON') : chalk.yellow('Production mode is OFF'));
162167
console.logAlways(this.config.strict ? chalk.green('Strict mode is ON') : chalk.yellow('Strict mode is OFF'));

‎lib/Cluster.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ 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) {
24+
if (process.env.NODE_ENV !== 'test' && Cluster.isVerbose()) {
2525
originalConsole.log(Cluster.workerID() + ' '.repeat(currentIndent), ...args);
2626
}
2727
},
@@ -31,7 +31,7 @@ const prefixedConsole = {
3131
}
3232
},
3333
warn(...args) {
34-
if (process.env.NODE_ENV !== 'test' && Cluster.verbose) {
34+
if (process.env.NODE_ENV !== 'test' && Cluster.isVerbose()) {
3535
originalConsole.warn(Cluster.workerID() + ' '.repeat(currentIndent), ...args);
3636
}
3737
},
@@ -41,13 +41,13 @@ const prefixedConsole = {
4141
}
4242
},
4343
group(...args) {
44-
if (process.env.NODE_ENV !== 'test' && Cluster.verbose) {
44+
if (process.env.NODE_ENV !== 'test' && Cluster.isVerbose()) {
4545
originalConsole.log(Cluster.workerID(), chalk.blue.bold(...args));
4646
currentIndent += indentAmount;
4747
}
4848
},
4949
groupEnd() {
50-
if (process.env.NODE_ENV !== 'test' && Cluster.verbose) {
50+
if (process.env.NODE_ENV !== 'test' && Cluster.isVerbose()) {
5151
currentIndent -= indentAmount;
5252
}
5353
},
@@ -57,8 +57,6 @@ const prefixedConsole = {
5757
const Cluster = {
5858
console: prefixedConsole,
5959

60-
verbose: true,
61-
6260
/* Create an access log line */
6361
logger(tokens, request, response) {
6462
if (process.env.NODE_ENV !== 'test') {
@@ -84,6 +82,11 @@ const Cluster = {
8482
console.log(`${chalk.magenta(`Worker ${cluster.worker ? cluster.worker.id : 0} (${pid})`)} now listening on port ${port}`);
8583
}
8684
},
85+
86+
/* Return whether verbose logging is on or off */
87+
isVerbose() {
88+
return process.env.VERBOSE_LOGGING !== 'false';
89+
},
8790
};
8891

8992
export { prefixedConsole as console };

0 commit comments

Comments
 (0)
Please sign in to comment.