intercept logs by adding the name only
This commit is contained in:
parent
c9590d476c
commit
75a7b93d69
|
@ -29,7 +29,8 @@ var Plugin = function(options) {
|
|||
this.afterContractsDeployActions = [];
|
||||
this.onDeployActions = [];
|
||||
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.config = options.config;
|
||||
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() {
|
||||
if (this.currentContext.includes(constants.contexts.any) || this.acceptedContext.includes(constants.contexts.any)) {
|
||||
return true;
|
||||
|
@ -65,7 +82,7 @@ Plugin.prototype.loadPlugin = function() {
|
|||
}
|
||||
this.loaded = true;
|
||||
if (this.shouldInterceptLogs) {
|
||||
this.interceptLogs(this.pluginModule);
|
||||
this.setUpLogger();
|
||||
}
|
||||
(this.pluginModule.call(this, this));
|
||||
};
|
||||
|
@ -85,37 +102,6 @@ Plugin.prototype.pathToFile = function(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
|
||||
Plugin.prototype.registerClientWeb3Provider = function(cb) {
|
||||
this.clientWeb3Providers.push(cb);
|
||||
|
|
|
@ -9,6 +9,7 @@ module.exports = function (embark) {
|
|||
return Haml.render(opts.source);
|
||||
});
|
||||
|
||||
embark.logger.info('patente', 'a goosee');
|
||||
embark.registerContractConfiguration({
|
||||
"default": {
|
||||
"contracts": {
|
||||
|
@ -25,17 +26,9 @@ module.exports = function (embark) {
|
|||
|
||||
embark.registerActionForEvent("deploy:contract:beforeDeploy", (params, cb) => {
|
||||
embark.logger.info("applying beforeDeploy plugin...");
|
||||
//console.dir(params);
|
||||
//console.dir(cb);
|
||||
//console.dir('------------------');
|
||||
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) => {
|
||||
if (cmd === "hello") {
|
||||
return "hello there!";
|
||||
|
@ -45,7 +38,7 @@ module.exports = function (embark) {
|
|||
});
|
||||
|
||||
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