From e14d5e64a91829e1a85a2713d9d90674eef5e23a Mon Sep 17 00:00:00 2001 From: Iuri Matias Date: Tue, 12 Nov 2019 13:38:44 -0500 Subject: [PATCH] fix rebase issues --- packages/core/core/src/engine.ts | 8 ++--- packages/core/core/src/events.ts | 50 +------------------------------ packages/core/core/src/plugins.ts | 28 ++++++++++++----- 3 files changed, 26 insertions(+), 60 deletions(-) diff --git a/packages/core/core/src/engine.ts b/packages/core/core/src/engine.ts index 24743593b..a82be6f04 100644 --- a/packages/core/core/src/engine.ts +++ b/packages/core/core/src/engine.ts @@ -7,10 +7,7 @@ import { ServicesMonitor } from './services_monitor'; import { normalizeInput } from 'embark-utils'; import { Logger } from 'embark-logger'; - -const utils = require('../utils/utils'); -const Logger = require('embark-logger'); -const DebugLog = require('embark-structlog'); +import { DebugLog } from 'embark-structlog'; const EMBARK_PROCESS_NAME = 'embark'; @@ -62,6 +59,8 @@ export class Engine { isDev: boolean | undefined; + debugLog: any; + constructor(options) { this.env = options.env; this.client = options.client; @@ -83,6 +82,7 @@ export class Engine { init(_options, callback) { callback = callback || function() {}; + const options = _options || {}; this.debugLog = new DebugLog("embark"); diff --git a/packages/core/core/src/events.ts b/packages/core/core/src/events.ts index 23f6d9847..c4a029de5 100644 --- a/packages/core/core/src/events.ts +++ b/packages/core/core/src/events.ts @@ -2,12 +2,6 @@ import { __ } from 'embark-i18n'; const EventEmitter = require('events'); const cloneDeep = require('lodash.clonedeep'); -const fs = require('fs-extra'); - -function debugEventsEnabled() { - return process && process.env && process.env.DEBUGEVENTS; -} - function warnIfLegacy(eventName: string) { const legacyEvents: string[] = []; if (legacyEvents.indexOf(eventName) >= 0) { @@ -15,44 +9,6 @@ function warnIfLegacy(eventName: string) { } } -function getOrigin(override) { - let origin = ((new Error().stack).split("at ")[3]).trim(); - origin = origin.split("(")[0].trim(); - return origin; -} - -function log(eventType, eventName, origin?: string) { - if (!(debugEventsEnabled())) { return; } - if (['end', 'prefinish', 'error', 'new', 'demo', 'block', 'version'].indexOf(eventName) >= 0) { - return; - } - if (eventName.indexOf("log") >= 0) { - return; - } - - // fs.appendFileSync(".embark/events.log", (new Error().stack) + "\n"); - if (!origin && origin !== "") { - const stack = new Error().stack; - if (stack) { - origin = stack.split("at ")[3].trim(); - origin = origin.split("(")[0].trim(); - } - // origin = getOrigin(); - } - - fs.ensureDirSync(".embark/"); - fs.appendFileSync(".embark/events.log", eventType + ": " + eventName + " -- (" + origin + ")\n"); -} - -// const cmdNames = {}; -// -// function trackCmd(cmdName) { -// if (!(process && process.env && process.env.DEBUGEVENTS)) return; -// let origin = ((new Error().stack).split("at ")[3]).trim(); -// origin = origin.split("(")[0].trim(); -// cmdNames[cmdName] = origin; -// } - export class EmbarkEmitter extends EventEmitter { constructor(options) { @@ -74,10 +30,6 @@ export class EmbarkEmitter extends EventEmitter { } } -// EmbarkEmitter.prototype.log = log; -EmbarkEmitter.prototype.log = log; -EmbarkEmitter.prototype.getOrigin = getOrigin; - EmbarkEmitter.prototype._maxListeners = 350; const _on = EmbarkEmitter.prototype.on; const _once = EmbarkEmitter.prototype.once; @@ -146,7 +98,7 @@ EmbarkEmitter.prototype.request2 = function() { this._emit('request:' + requestName, ...other_args); }); - let ogStack = this.debugLog.getStackTrace(); + const ogStack = this.debugLog.getStackTrace(); promise.catch((e) => { if (this.debugLog.isEnabled()) { diff --git a/packages/core/core/src/plugins.ts b/packages/core/core/src/plugins.ts index 91f4bf473..5be223cbb 100644 --- a/packages/core/core/src/plugins.ts +++ b/packages/core/core/src/plugins.ts @@ -29,6 +29,8 @@ export class Plugins { version: string; + debugLog: any; + static deprecated = { 'embarkjs-connector-web3': '4.1.0' }; @@ -40,6 +42,7 @@ export class Plugins { this.logger = options.logger; this.events = options.events; this.config = options.config; + this.debugLog = options.debugLog; this.context = options.context; this.fs = fs; this.env = options.env; @@ -76,6 +79,7 @@ export class Plugins { pluginModule: plugin, pluginConfig, logger: this.logger, + debugLog: this.debugLog, pluginPath, interceptLogs: this.interceptLogs, events: this.events, @@ -108,6 +112,7 @@ export class Plugins { pluginModule: plugin, pluginConfig: pluginConfig || {}, logger: this.logger, + debugLog: this.debugLog, pluginPath, interceptLogs: this.interceptLogs, events: this.events, @@ -131,11 +136,18 @@ export class Plugins { plugin = plugin.default; } + let logId = this.debugLog.moduleInit(pluginName); + let events = this.debugLog.tagObject(this.events, logId); + let logger = this.debugLog.tagObject(this.logger, logId); + const pluginWrapper = new Plugin({ name: pluginName, pluginModule: plugin, pluginConfig, logger: this.logger, + debugLog: this.debugLog, + logId: logId, + events: events, pluginPath, interceptLogs: this.interceptLogs, events: this.events, @@ -230,7 +242,7 @@ export class Plugins { } // TODO: because this is potentially hanging, we should issue a trace warning if the event does not exists - runActionsForEvent(eventName, args, cb) { + runActionsForEvent(eventName, args, cb, logId) { const self = this; if (typeof (args) === 'function') { cb = args; @@ -254,31 +266,33 @@ export class Plugins { return 0; }); - this.events.log("ACTION", eventName, ""); + this.debugLog.log({parent_id: logId, type: "trigger_action", name: eventName, givenLogId: logId, plugins: actionPlugins, inputs: args}); async.reduce(actionPlugins, args, function(current_args, pluginObj: any, nextEach) { const [plugin, pluginName] = pluginObj; - self.events.log("== ACTION FOR " + eventName, plugin.action.name, pluginName); + let actionLogId = self.debugLog.log({module: pluginName, type: "action_run", name: (eventName + plugin.name), source: pluginName, inputs: current_args}); if (typeof (args) === 'function') { plugin.action.call(plugin.action, (...params) => { - nextEach(...params || current_args); + self.debugLog.log({id: actionLogId, outputs: params || current_args}); + return nextEach(...params || current_args); }); } else { plugin.action.call(plugin.action, args, (...params) => { - nextEach(...params || current_args); + self.debugLog.log({id: actionLogId, outputs: (args, params || current_args)}); + return nextEach(...params || current_args); }); } }, cb); } - emitAndRunActionsForEvent(eventName, args, cb) { + emitAndRunActionsForEvent(eventName, args, cb, logId) { if (typeof (args) === 'function') { cb = args; args = []; } this.events.emit(eventName, args); - return this.runActionsForEvent(eventName, args, cb); + return this.runActionsForEvent(eventName, args, cb, logId); } }