mirror of https://github.com/embarklabs/embark.git
intercept logs by adding the name only
This commit is contained in:
parent
cd4bce8d12
commit
7f2f841e28
|
@ -29,7 +29,8 @@ var Plugin = function(options) {
|
||||||
this.afterContractsDeployActions = [];
|
this.afterContractsDeployActions = [];
|
||||||
this.onDeployActions = [];
|
this.onDeployActions = [];
|
||||||
this.eventActions = {};
|
this.eventActions = {};
|
||||||
this.logger = options.logger;
|
this._loggerObject = options.logger;
|
||||||
|
this.logger = this._loggerObject; // Might get changed if we do intercept
|
||||||
this.events = options.events;
|
this.events = options.events;
|
||||||
this.config = options.config;
|
this.config = options.config;
|
||||||
this.env = options.env;
|
this.env = options.env;
|
||||||
|
@ -45,6 +46,22 @@ var Plugin = function(options) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Plugin.prototype._log = function(type) {
|
||||||
|
this._loggerObject[type](this.name + ':', ...[].slice.call(arguments, 1));
|
||||||
|
};
|
||||||
|
|
||||||
|
Plugin.prototype.setUpLogger = function () {
|
||||||
|
this.logger = {
|
||||||
|
log: this._log.bind(this, 'log'),
|
||||||
|
warn: this._log.bind(this, 'warn'),
|
||||||
|
error: this._log.bind(this, 'error'),
|
||||||
|
info: this._log.bind(this, 'info'),
|
||||||
|
debug: this._log.bind(this, 'debug'),
|
||||||
|
trace: this._log.bind(this, 'trace'),
|
||||||
|
dir: this._log.bind(this, 'dir')
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
Plugin.prototype.isContextValid = function() {
|
Plugin.prototype.isContextValid = function() {
|
||||||
if (this.currentContext.includes(constants.contexts.any) || this.acceptedContext.includes(constants.contexts.any)) {
|
if (this.currentContext.includes(constants.contexts.any) || this.acceptedContext.includes(constants.contexts.any)) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -65,7 +82,7 @@ Plugin.prototype.loadPlugin = function() {
|
||||||
}
|
}
|
||||||
this.loaded = true;
|
this.loaded = true;
|
||||||
if (this.shouldInterceptLogs) {
|
if (this.shouldInterceptLogs) {
|
||||||
this.interceptLogs(this.pluginModule);
|
this.setUpLogger();
|
||||||
}
|
}
|
||||||
(this.pluginModule.call(this, this));
|
(this.pluginModule.call(this, this));
|
||||||
};
|
};
|
||||||
|
@ -85,37 +102,6 @@ Plugin.prototype.pathToFile = function(filename) {
|
||||||
return utils.joinPath(this.pluginPath, filename);
|
return utils.joinPath(this.pluginPath, filename);
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin.prototype.interceptLogs = function(context) {
|
|
||||||
var self = this;
|
|
||||||
// TODO: this is a bit nasty, figure out a better way
|
|
||||||
context.console = context.console || console;
|
|
||||||
|
|
||||||
//context.console.error = function(txt) {
|
|
||||||
// // TODO: logger should support an array instead of a single argument
|
|
||||||
// //self.logger.error.apply(self.logger, arguments);
|
|
||||||
// self.logger.error(self.name + " > " + txt);
|
|
||||||
//};
|
|
||||||
context.console.log = function(txt) {
|
|
||||||
self.logger.info(self.name + " > " + txt);
|
|
||||||
};
|
|
||||||
context.console.warn = function(txt) {
|
|
||||||
self.logger.warn(self.name + " > " + txt);
|
|
||||||
};
|
|
||||||
context.console.info = function(txt) {
|
|
||||||
self.logger.info(self.name + " > " + txt);
|
|
||||||
};
|
|
||||||
context.console.debug = function(txt) {
|
|
||||||
// TODO: ue JSON.stringify
|
|
||||||
self.logger.debug(self.name + " > " + txt);
|
|
||||||
};
|
|
||||||
context.console.trace = function(txt) {
|
|
||||||
self.logger.trace(self.name + " > " + txt);
|
|
||||||
};
|
|
||||||
context.console.dir = function(txt) {
|
|
||||||
self.logger.dir(txt);
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: add deploy provider
|
// TODO: add deploy provider
|
||||||
Plugin.prototype.registerClientWeb3Provider = function(cb) {
|
Plugin.prototype.registerClientWeb3Provider = function(cb) {
|
||||||
this.clientWeb3Providers.push(cb);
|
this.clientWeb3Providers.push(cb);
|
||||||
|
|
|
@ -9,6 +9,7 @@ module.exports = function (embark) {
|
||||||
return Haml.render(opts.source);
|
return Haml.render(opts.source);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
embark.logger.info('patente', 'a goosee');
|
||||||
embark.registerContractConfiguration({
|
embark.registerContractConfiguration({
|
||||||
"default": {
|
"default": {
|
||||||
"contracts": {
|
"contracts": {
|
||||||
|
@ -25,17 +26,9 @@ module.exports = function (embark) {
|
||||||
|
|
||||||
embark.registerActionForEvent("deploy:contract:beforeDeploy", (params, cb) => {
|
embark.registerActionForEvent("deploy:contract:beforeDeploy", (params, cb) => {
|
||||||
embark.logger.info("applying beforeDeploy plugin...");
|
embark.logger.info("applying beforeDeploy plugin...");
|
||||||
//console.dir(params);
|
|
||||||
//console.dir(cb);
|
|
||||||
//console.dir('------------------');
|
|
||||||
cb();
|
cb();
|
||||||
});
|
});
|
||||||
|
|
||||||
// NOTE: uncommenting this will make dappConnection stop working
|
|
||||||
//embark.registerClientWeb3Provider(function(options) {
|
|
||||||
// return "web3 = new Web3(new Web3.providers.HttpProvider('http://" + options.rpcHost + ":" + options.rpcPort + "'));";
|
|
||||||
//});
|
|
||||||
|
|
||||||
embark.registerConsoleCommand((cmd) => {
|
embark.registerConsoleCommand((cmd) => {
|
||||||
if (cmd === "hello") {
|
if (cmd === "hello") {
|
||||||
return "hello there!";
|
return "hello there!";
|
||||||
|
@ -45,7 +38,7 @@ module.exports = function (embark) {
|
||||||
});
|
});
|
||||||
|
|
||||||
embark.events.on("contractsDeployed", function() {
|
embark.events.on("contractsDeployed", function() {
|
||||||
embark.logger.info("plugin says: your contracts have been deployed");
|
embark.logger.info("plugin says:", ' your contracts have been deployed');
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue