mirror of
https://github.com/embarklabs/embark.git
synced 2025-02-16 15:47:25 +00:00
refactor to remove debug events logging and move them to the new logger
This commit is contained in:
parent
7f6d0009a3
commit
d364bb0401
@ -22,6 +22,7 @@ class SuperLog {
|
||||
|
||||
// TODO: make this a flag depending on ENV var or constructor
|
||||
isEnabled() {
|
||||
//return process && process.env && process.env.DEBUGLOGS;
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -40,6 +41,7 @@ class SuperLog {
|
||||
}
|
||||
|
||||
startSession() {
|
||||
if (!this.isEnabled()) return;
|
||||
this.session = uuid.v4();
|
||||
|
||||
this.modules = {}
|
||||
@ -55,6 +57,7 @@ class SuperLog {
|
||||
}
|
||||
|
||||
moduleInit(name) {
|
||||
if (!this.isEnabled()) return;
|
||||
let id = uuid.v4();
|
||||
|
||||
this.addRecord({
|
||||
@ -64,7 +67,8 @@ class SuperLog {
|
||||
parent_id: this.session,
|
||||
type: 'module_init',
|
||||
value: name,
|
||||
name: name
|
||||
name: name,
|
||||
stack: this.getStackTrace()
|
||||
})
|
||||
|
||||
this.modules[name] = id
|
||||
@ -72,7 +76,14 @@ class SuperLog {
|
||||
return id;
|
||||
}
|
||||
|
||||
getStackTrace() {
|
||||
if (!this.isEnabled()) return;
|
||||
return (new Error().stack).split('\n');
|
||||
}
|
||||
|
||||
log(values) {
|
||||
if (!this.isEnabled()) return;
|
||||
|
||||
if (values.id) {
|
||||
this.updateRecord(values.id, values)
|
||||
return values.id;
|
||||
@ -86,6 +97,10 @@ class SuperLog {
|
||||
values.parent_id = this.session
|
||||
}
|
||||
|
||||
if (!values.stack) {
|
||||
values.stack = this.getStackTrace();
|
||||
}
|
||||
|
||||
this.addRecord({
|
||||
session: this.session,
|
||||
timestamp: Date.now(),
|
||||
@ -97,6 +112,7 @@ class SuperLog {
|
||||
}
|
||||
|
||||
info() {
|
||||
if (!this.isEnabled()) return;
|
||||
let id = uuid.v4();
|
||||
this.log({
|
||||
session: this.session,
|
||||
|
@ -2,12 +2,6 @@ import { __ } from 'embark-i18n';
|
||||
var 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) {
|
||||
const legacyEvents = [];
|
||||
if (legacyEvents.indexOf(eventName) >= 0) {
|
||||
@ -15,32 +9,6 @@ function warnIfLegacy(eventName) {
|
||||
}
|
||||
}
|
||||
|
||||
function getOrigin(override) {
|
||||
let origin = ((new Error().stack).split("at ")[3]).trim();
|
||||
origin = origin.split("(")[0].trim();
|
||||
return origin;
|
||||
}
|
||||
|
||||
function log(eventType, eventName, origin) {
|
||||
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 !== "") {
|
||||
origin = ((new Error().stack).split("at ")[3]).trim();
|
||||
origin = origin.split("(")[0].trim();
|
||||
// origin = getOrigin();
|
||||
}
|
||||
|
||||
fs.ensureDirSync(".embark/");
|
||||
fs.appendFileSync(".embark/events.log", eventType + ": " + eventName + " -- (" + origin + ")\n");
|
||||
}
|
||||
|
||||
class EmbarkEmitter extends EventEmitter {
|
||||
|
||||
constructor(options) {
|
||||
@ -52,16 +20,10 @@ class EmbarkEmitter extends EventEmitter {
|
||||
|
||||
emit(requestName, ...args) {
|
||||
warnIfLegacy(arguments[0]);
|
||||
// log("\n|event", requestName);
|
||||
return super.emit(requestName, ...args);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 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;
|
||||
@ -79,19 +41,16 @@ EmbarkEmitter.prototype.removeAllListeners = function(requestName) {
|
||||
};
|
||||
|
||||
EmbarkEmitter.prototype.on = function(requestName, cb) {
|
||||
// log("EVENT LISTEN", requestName);
|
||||
warnIfLegacy(requestName);
|
||||
return _on.call(this, requestName, cb);
|
||||
};
|
||||
|
||||
EmbarkEmitter.prototype.once = function(requestName, cb) {
|
||||
// log("EVENT LISTEN ONCE", requestName);
|
||||
warnIfLegacy(requestName);
|
||||
return _once.call(this, requestName, cb);
|
||||
};
|
||||
|
||||
EmbarkEmitter.prototype.setHandler = function(requestName, cb) {
|
||||
// log("SET HANDLER", requestName);
|
||||
warnIfLegacy(requestName);
|
||||
return _setHandler.call(this, requestName, cb);
|
||||
};
|
||||
@ -102,12 +61,11 @@ EmbarkEmitter.prototype.request2 = function() {
|
||||
|
||||
let requestId = this.debugLog.log({parent_id: this.logId, type: "request", name: requestName, inputs: other_args});
|
||||
|
||||
// log("\nREQUEST", requestName);
|
||||
warnIfLegacy(requestName);
|
||||
if (this._events && !this._events['request:' + requestName]) {
|
||||
|
||||
if (this.debugLog.isEnabled()) {
|
||||
this.debugLog.log({ id: requestId, error: "no request listener for " + requestName, source: this.getOrigin()})
|
||||
this.debugLog.log({ id: requestId, error: "no request listener for " + requestName})
|
||||
// KEPT for now until api refactor separating requests from commands
|
||||
console.log("made request without listener: " + requestName);
|
||||
console.trace();
|
||||
@ -133,10 +91,7 @@ EmbarkEmitter.prototype.request2 = function() {
|
||||
this._emit('request:' + requestName, ...other_args);
|
||||
});
|
||||
|
||||
let ogStack;
|
||||
if (this.debugLog.isEnabled()) {
|
||||
ogStack = (new Error().stack);
|
||||
}
|
||||
let ogStack = this.debugLog.getStackTrace();
|
||||
|
||||
promise.catch((e) => {
|
||||
if (this.debugLog.isEnabled()) {
|
||||
@ -144,7 +99,7 @@ EmbarkEmitter.prototype.request2 = function() {
|
||||
console.dir(ogStack);
|
||||
}
|
||||
|
||||
this.debugLog.log({id: requestId, error: "promise exception", outputs: ogStack, source: ogStack})
|
||||
this.debugLog.log({id: requestId, error: "promise exception", outputs: ogStack, stack: ogStack})
|
||||
return e;
|
||||
});
|
||||
|
||||
@ -155,14 +110,8 @@ EmbarkEmitter.prototype.request = function() {
|
||||
let requestName = arguments[0];
|
||||
let other_args = [].slice.call(arguments, 1);
|
||||
|
||||
let origin;
|
||||
if (this.debugLog.isEnabled) {
|
||||
origin = this.getOrigin();
|
||||
}
|
||||
let requestId = this.debugLog.log({parent_id: this.logId, type: "old_request", name: requestName, inputs: other_args})
|
||||
|
||||
let requestId = this.debugLog.log({parent_id: this.logId, type: "old_request", name: requestName, inputs: other_args, source: origin})
|
||||
|
||||
// log("\nREQUEST(OLD)", requestName);
|
||||
warnIfLegacy(requestName);
|
||||
if (this._events && !this._events['request:' + requestName]) {
|
||||
if (this.debugLog.isEnabled()) {
|
||||
@ -194,16 +143,10 @@ EmbarkEmitter.prototype.setCommandHandler = function(requestName, cb) {
|
||||
// log("SET COMMAND HANDLER", requestName);
|
||||
|
||||
let requestId = this.debugLog.log({parent_id: this.logId, type: "setCommandHandler", name: requestName})
|
||||
|
||||
// let origin = ((new Error().stack).split("at ")[3]).trim();
|
||||
// origin = origin.split("(")[0].trim();
|
||||
let origin;
|
||||
if (this.debugLog.isEnabled()) {
|
||||
origin = this.getOrigin();
|
||||
}
|
||||
let origin = this.debugLog.getStackTrace();
|
||||
|
||||
let listener = function(_cb) {
|
||||
this.debugLog.log({id: requestId, output: origin, source: origin});
|
||||
this.debugLog.log({id: requestId, output: origin, stack: origin});
|
||||
// log("== REQUEST RESPONSE", requestName, origin);
|
||||
cb.call(this, ...arguments);
|
||||
};
|
||||
@ -234,8 +177,6 @@ EmbarkEmitter.prototype.setCommandHandler = function(requestName, cb) {
|
||||
|
||||
// TODO: deprecated/remove this
|
||||
EmbarkEmitter.prototype.setCommandHandlerOnce = function(requestName, cb) {
|
||||
// log("SET COMMAND HANDLER ONCE", requestName);
|
||||
|
||||
const listenerName = 'request:' + requestName;
|
||||
|
||||
// if this event was requested prior to the command handler
|
||||
|
@ -227,12 +227,7 @@ Plugins.prototype.runActionsForEvent = function(eventName, args, cb, logId) {
|
||||
return cb(null, args);
|
||||
}
|
||||
|
||||
let origin;
|
||||
if (this.debugLog.isEnabled()) {
|
||||
origin = this.events.getOrigin();
|
||||
}
|
||||
|
||||
this.debugLog.log({parent_id: logId, type: "trigger_action", name: eventName, source: origin, givenLogId: logId, plugins: actionPlugins, inputs: args});
|
||||
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, nextEach) {
|
||||
const [plugin, pluginName] = pluginObj;
|
||||
|
Loading…
x
Reference in New Issue
Block a user