mirror of
https://github.com/embarklabs/embark.git
synced 2025-03-01 05:40:44 +00:00
refactor to remove debug events logging and move them to the new logger
This commit is contained in:
parent
ef9daa0d74
commit
5c8ca0a0d8
@ -64,7 +64,6 @@ export class EmbarkEmitter extends EventEmitter {
|
||||
|
||||
emit(requestName, ...args) {
|
||||
warnIfLegacy(arguments[0]);
|
||||
// log("\n|event", requestName);
|
||||
return super.emit(requestName, ...args);
|
||||
}
|
||||
}
|
||||
@ -90,19 +89,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);
|
||||
};
|
||||
@ -113,12 +109,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();
|
||||
@ -145,10 +140,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()) {
|
||||
@ -156,7 +148,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;
|
||||
});
|
||||
|
||||
@ -167,14 +159,8 @@ EmbarkEmitter.prototype.request = function() {
|
||||
const requestName = arguments[0];
|
||||
const 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()) {
|
||||
@ -206,16 +192,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();
|
||||
|
||||
const 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);
|
||||
};
|
||||
@ -246,8 +226,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
|
||||
|
@ -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,
|
||||
|
@ -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