Skip to content

Commit e33eef8

Browse files
committed
feat(logs): Support escalating log levels, 'debug', 'info', 'warning', 'error', as well as 'quiet'
backwards compatible with boolean debug
1 parent b934043 commit e33eef8

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

core/lib/patternlab.js

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,6 @@ let serve = require('./serve'); // eslint-disable-line
4141
const pattern_assembler = new pa();
4242
const lineage_hunter = new lh();
4343

44-
//register our log events
45-
plutils.log.on('error', msg => console.log(msg));
46-
plutils.log.on('debug', msg => console.log(msg));
47-
plutils.log.on('warning', msg => console.log(msg));
48-
plutils.log.on('info', msg => console.log(msg));
49-
5044
const patternEngines = require('./pattern_engines');
5145
const EventEmitter = require('events').EventEmitter;
5246

@@ -64,6 +58,9 @@ class PatternLab {
6458
// Make ye olde event emitter
6559
this.events = new PatternLabEventEmitter();
6660

61+
//register our log events
62+
this.registerLogger(config.debug);
63+
6764
// Make a place for the pattern graph to sit
6865
this.graph = null;
6966

@@ -247,6 +244,39 @@ class PatternLab {
247244
//write the compiled template to the public patterns directory
248245
outputFiles.forEach(outFile => fs.outputFileSync(outFile.path, outFile.content));
249246
}
247+
248+
249+
250+
/**
251+
* Binds console logging to different levels
252+
*
253+
* @param {string} logLevel
254+
* @memberof PatternLab
255+
*/
256+
registerLogger(logLevel) {
257+
258+
// handle the legacy value, which is boolean
259+
if (typeof logLevel === 'boolean') {
260+
if (logLevel) {
261+
plutils.log.on('debug', msg => console.log(msg));
262+
}
263+
plutils.log.on('info', msg => console.log(msg));
264+
plutils.log.on('warning', msg => console.log(msg));
265+
plutils.log.on('error', msg => console.log(msg));
266+
} else {
267+
if ( logLevel === 'quiet') { return; }
268+
switch (logLevel) {
269+
case 'debug':
270+
plutils.log.on('debug', msg => console.log(msg));
271+
case 'info':
272+
plutils.log.on('info', msg => console.log(msg));
273+
case 'warning':
274+
plutils.log.on('warning', msg => console.log(msg));
275+
case 'error':
276+
plutils.log.on('error', msg => console.log(msg));
277+
}
278+
}
279+
}
250280
}
251281

252282
//bootstrap update notifier
@@ -320,6 +350,7 @@ function processAllPatternsRecursive(patterns_dir, patternlab) {
320350
}
321351

322352
function checkConfiguration(patternlab) {
353+
323354
//default the output suffixes if not present
324355
const outputFileSuffixes = {
325356
rendered: '.rendered',

0 commit comments

Comments
 (0)