improve logging

This commit is contained in:
Jonathan Rainville 2018-05-08 11:31:47 -04:00
parent 7d64b705a3
commit dc7a002c1e
2 changed files with 24 additions and 21 deletions

View File

@ -189,6 +189,9 @@ class Engine {
} }
if (msg.result === constants.pipeline.log) { 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)); self.logger.debug(self.normalizeInput(msg.message));
} }
}); });

View File

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