diff --git a/lib/core/engine.js b/lib/core/engine.js index 7609a3a7..6106dbde 100644 --- a/lib/core/engine.js +++ b/lib/core/engine.js @@ -189,6 +189,9 @@ class Engine { } if (msg.result === constants.pipeline.log) { + if (self.logger[msg.type]) { + return self.logger[msg.type](self.normalizeInput(msg.message)); + } self.logger.debug(self.normalizeInput(msg.message)); } }); diff --git a/lib/pipeline/pipeline.js b/lib/pipeline/pipeline.js index d69e21b3..dace18d6 100644 --- a/lib/pipeline/pipeline.js +++ b/lib/pipeline/pipeline.js @@ -39,16 +39,16 @@ class Pipeline { const context = {}; context.console = console; - context.console.log = this.log; - context.console.warn = this.log; - context.console.info = this.log; - context.console.debug = this.log; - context.console.trace = this.log; - context.console.dir = this.log; + context.console.log = this.log.bind(this, 'log'); + context.console.warn = this.log.bind(this, 'warn'); + context.console.info = this.log.bind(this, 'info'); + context.console.debug = this.log.bind(this, 'debug'); + context.console.trace = this.log.bind(this, 'trace'); + context.console.dir = this.log.bind(this, 'dir'); } - log() { - process.send({result: constants.pipeline.log, message: arguments}); + log(type, ...messages) { + process.send({result: constants.pipeline.log, message: messages, type}); } build(abi, contractsJSON, path, callback) { @@ -89,7 +89,7 @@ class Pipeline { async.mapLimit(files, 1, function (file, fileCb) { file = new File(file); // Re-instantiate a File as through the process, we lose its prototype - self.log("reading " + file.filename); + console.trace("reading " + file.filename); if (file.filename.indexOf('.js') < 0) { return file.content(function (fileContent) { @@ -124,7 +124,7 @@ class Pipeline { function checkFile(next) { fs.access('./.embark/' + file.filename, (err) => { if (err) { - self.log("couldn't find file: " + file.filename); + console.error("couldn't find file: " + file.filename); return next("couldn't find file: " + file.filename); } next(); @@ -147,7 +147,7 @@ class Pipeline { ], function (err, contentFile) { if (err) { process.chdir(realCwd); - self.log(err); + console.error(err); return fileCb(err); } @@ -156,10 +156,10 @@ class Pipeline { }, function (err, contentFiles) { if (err) { - self.log('errors found while generating ' + targetFile); + console.error('errors found while generating ' + targetFile); } let dir = targetFile.split('/').slice(0, -1).join('/'); - self.log("creating dir " + self.buildDir + dir); + console.trace("creating dir " + self.buildDir + dir); fs.mkdirpSync(self.buildDir + dir); // if it's a directory @@ -172,7 +172,7 @@ class Pipeline { async.each(contentFiles, function (file, mapCb) { let filename = file.filename.replace(file.basedir + '/', ''); - self.log("writing file " + (self.buildDir + targetDir + filename).bold.dim); + console.info("writing file " + (self.buildDir + targetDir + filename).bold.dim); fs.copy(file.path, self.buildDir + targetDir + filename, {overwrite: true}, mapCb); }, cb); @@ -186,7 +186,7 @@ class Pipeline { return file.content; }).join("\n"); - self.log("writing file " + (self.buildDir + targetFile).bold.dim); + console.info("writing file " + (self.buildDir + targetFile).bold.dim); fs.writeFile(self.buildDir + targetFile, content, cb); } ); @@ -219,7 +219,7 @@ class Pipeline { }, function (err) { if (err) { - self.log(err.message); + console.error(err.message); } return fileCb(null, { content: fileContent, @@ -283,16 +283,16 @@ class Pipeline { }; } - webpack(webpackOptions).run((_err, _stats) => { - if (_err) { - console.log(_err); + webpack(webpackOptions).run((err, stats) => { + if (err) { + console.error(err); } if (!detectErrors) { return callback(); } - if (_stats.hasErrors()) { - return callback(_stats.toJson().errors.join("\n")); + if (stats.hasErrors()) { + return callback(stats.toJson().errors.join("\n")); } callback(); });