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) {
|
emit(requestName, ...args) {
|
||||||
warnIfLegacy(arguments[0]);
|
warnIfLegacy(arguments[0]);
|
||||||
// log("\n|event", requestName);
|
|
||||||
return super.emit(requestName, ...args);
|
return super.emit(requestName, ...args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -90,19 +89,16 @@ EmbarkEmitter.prototype.removeAllListeners = function(requestName) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
EmbarkEmitter.prototype.on = function(requestName, cb) {
|
EmbarkEmitter.prototype.on = function(requestName, cb) {
|
||||||
// log("EVENT LISTEN", requestName);
|
|
||||||
warnIfLegacy(requestName);
|
warnIfLegacy(requestName);
|
||||||
return _on.call(this, requestName, cb);
|
return _on.call(this, requestName, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkEmitter.prototype.once = function(requestName, cb) {
|
EmbarkEmitter.prototype.once = function(requestName, cb) {
|
||||||
// log("EVENT LISTEN ONCE", requestName);
|
|
||||||
warnIfLegacy(requestName);
|
warnIfLegacy(requestName);
|
||||||
return _once.call(this, requestName, cb);
|
return _once.call(this, requestName, cb);
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkEmitter.prototype.setHandler = function(requestName, cb) {
|
EmbarkEmitter.prototype.setHandler = function(requestName, cb) {
|
||||||
// log("SET HANDLER", requestName);
|
|
||||||
warnIfLegacy(requestName);
|
warnIfLegacy(requestName);
|
||||||
return _setHandler.call(this, requestName, cb);
|
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});
|
let requestId = this.debugLog.log({parent_id: this.logId, type: "request", name: requestName, inputs: other_args});
|
||||||
|
|
||||||
// log("\nREQUEST", requestName);
|
|
||||||
warnIfLegacy(requestName);
|
warnIfLegacy(requestName);
|
||||||
if (this._events && !this._events['request:' + requestName]) {
|
if (this._events && !this._events['request:' + requestName]) {
|
||||||
|
|
||||||
if (this.debugLog.isEnabled()) {
|
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
|
// KEPT for now until api refactor separating requests from commands
|
||||||
console.log("made request without listener: " + requestName);
|
console.log("made request without listener: " + requestName);
|
||||||
console.trace();
|
console.trace();
|
||||||
@ -145,10 +140,7 @@ EmbarkEmitter.prototype.request2 = function() {
|
|||||||
this._emit('request:' + requestName, ...other_args);
|
this._emit('request:' + requestName, ...other_args);
|
||||||
});
|
});
|
||||||
|
|
||||||
let ogStack;
|
let ogStack = this.debugLog.getStackTrace();
|
||||||
if (this.debugLog.isEnabled()) {
|
|
||||||
ogStack = (new Error().stack);
|
|
||||||
}
|
|
||||||
|
|
||||||
promise.catch((e) => {
|
promise.catch((e) => {
|
||||||
if (this.debugLog.isEnabled()) {
|
if (this.debugLog.isEnabled()) {
|
||||||
@ -156,7 +148,7 @@ EmbarkEmitter.prototype.request2 = function() {
|
|||||||
console.dir(ogStack);
|
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;
|
return e;
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -167,14 +159,8 @@ EmbarkEmitter.prototype.request = function() {
|
|||||||
const requestName = arguments[0];
|
const requestName = arguments[0];
|
||||||
const other_args = [].slice.call(arguments, 1);
|
const other_args = [].slice.call(arguments, 1);
|
||||||
|
|
||||||
let origin;
|
let requestId = this.debugLog.log({parent_id: this.logId, type: "old_request", name: requestName, inputs: other_args})
|
||||||
if (this.debugLog.isEnabled) {
|
|
||||||
origin = this.getOrigin();
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
warnIfLegacy(requestName);
|
||||||
if (this._events && !this._events['request:' + requestName]) {
|
if (this._events && !this._events['request:' + requestName]) {
|
||||||
if (this.debugLog.isEnabled()) {
|
if (this.debugLog.isEnabled()) {
|
||||||
@ -206,16 +192,10 @@ EmbarkEmitter.prototype.setCommandHandler = function(requestName, cb) {
|
|||||||
// log("SET COMMAND HANDLER", requestName);
|
// log("SET COMMAND HANDLER", requestName);
|
||||||
|
|
||||||
let requestId = this.debugLog.log({parent_id: this.logId, type: "setCommandHandler", name: requestName})
|
let requestId = this.debugLog.log({parent_id: this.logId, type: "setCommandHandler", name: requestName})
|
||||||
|
let origin = this.debugLog.getStackTrace();
|
||||||
// let origin = ((new Error().stack).split("at ")[3]).trim();
|
|
||||||
// origin = origin.split("(")[0].trim();
|
|
||||||
let origin;
|
|
||||||
if (this.debugLog.isEnabled()) {
|
|
||||||
origin = this.getOrigin();
|
|
||||||
}
|
|
||||||
|
|
||||||
const listener = function(_cb) {
|
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);
|
// log("== REQUEST RESPONSE", requestName, origin);
|
||||||
cb.call(this, ...arguments);
|
cb.call(this, ...arguments);
|
||||||
};
|
};
|
||||||
@ -246,8 +226,6 @@ EmbarkEmitter.prototype.setCommandHandler = function(requestName, cb) {
|
|||||||
|
|
||||||
// TODO: deprecated/remove this
|
// TODO: deprecated/remove this
|
||||||
EmbarkEmitter.prototype.setCommandHandlerOnce = function(requestName, cb) {
|
EmbarkEmitter.prototype.setCommandHandlerOnce = function(requestName, cb) {
|
||||||
// log("SET COMMAND HANDLER ONCE", requestName);
|
|
||||||
|
|
||||||
const listenerName = 'request:' + requestName;
|
const listenerName = 'request:' + requestName;
|
||||||
|
|
||||||
// if this event was requested prior to the command handler
|
// 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
|
// TODO: make this a flag depending on ENV var or constructor
|
||||||
isEnabled() {
|
isEnabled() {
|
||||||
|
//return process && process.env && process.env.DEBUGLOGS;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,6 +41,7 @@ class SuperLog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
startSession() {
|
startSession() {
|
||||||
|
if (!this.isEnabled()) return;
|
||||||
this.session = uuid.v4();
|
this.session = uuid.v4();
|
||||||
|
|
||||||
this.modules = {}
|
this.modules = {}
|
||||||
@ -55,6 +57,7 @@ class SuperLog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
moduleInit(name) {
|
moduleInit(name) {
|
||||||
|
if (!this.isEnabled()) return;
|
||||||
let id = uuid.v4();
|
let id = uuid.v4();
|
||||||
|
|
||||||
this.addRecord({
|
this.addRecord({
|
||||||
@ -64,7 +67,8 @@ class SuperLog {
|
|||||||
parent_id: this.session,
|
parent_id: this.session,
|
||||||
type: 'module_init',
|
type: 'module_init',
|
||||||
value: name,
|
value: name,
|
||||||
name: name
|
name: name,
|
||||||
|
stack: this.getStackTrace()
|
||||||
})
|
})
|
||||||
|
|
||||||
this.modules[name] = id
|
this.modules[name] = id
|
||||||
@ -72,7 +76,14 @@ class SuperLog {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getStackTrace() {
|
||||||
|
if (!this.isEnabled()) return;
|
||||||
|
return (new Error().stack).split('\n');
|
||||||
|
}
|
||||||
|
|
||||||
log(values) {
|
log(values) {
|
||||||
|
if (!this.isEnabled()) return;
|
||||||
|
|
||||||
if (values.id) {
|
if (values.id) {
|
||||||
this.updateRecord(values.id, values)
|
this.updateRecord(values.id, values)
|
||||||
return values.id;
|
return values.id;
|
||||||
@ -86,6 +97,10 @@ class SuperLog {
|
|||||||
values.parent_id = this.session
|
values.parent_id = this.session
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!values.stack) {
|
||||||
|
values.stack = this.getStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
this.addRecord({
|
this.addRecord({
|
||||||
session: this.session,
|
session: this.session,
|
||||||
timestamp: Date.now(),
|
timestamp: Date.now(),
|
||||||
@ -97,6 +112,7 @@ class SuperLog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
info() {
|
info() {
|
||||||
|
if (!this.isEnabled()) return;
|
||||||
let id = uuid.v4();
|
let id = uuid.v4();
|
||||||
this.log({
|
this.log({
|
||||||
session: this.session,
|
session: this.session,
|
||||||
|
@ -227,12 +227,7 @@ Plugins.prototype.runActionsForEvent = function(eventName, args, cb, logId) {
|
|||||||
return cb(null, args);
|
return cb(null, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
let origin;
|
this.debugLog.log({parent_id: logId, type: "trigger_action", name: eventName, givenLogId: logId, plugins: actionPlugins, inputs: args});
|
||||||
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});
|
|
||||||
|
|
||||||
async.reduce(actionPlugins, args, function (current_args, pluginObj, nextEach) {
|
async.reduce(actionPlugins, args, function (current_args, pluginObj, nextEach) {
|
||||||
const [plugin, pluginName] = pluginObj;
|
const [plugin, pluginName] = pluginObj;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user