mirror of https://github.com/embarklabs/embark.git
refactor to use new logs only instead of event logs
This commit is contained in:
parent
bd96a10193
commit
ef9daa0d74
|
@ -16,7 +16,6 @@ function warnIfLegacy(eventName: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function getOrigin(override) {
|
function getOrigin(override) {
|
||||||
if (!override && !(debugEventsEnabled())) return "";
|
|
||||||
let origin = ((new Error().stack).split("at ")[3]).trim();
|
let origin = ((new Error().stack).split("at ")[3]).trim();
|
||||||
origin = origin.split("(")[0].trim();
|
origin = origin.split("(")[0].trim();
|
||||||
return origin;
|
return origin;
|
||||||
|
@ -30,6 +29,7 @@ function log(eventType, eventName, origin?: string) {
|
||||||
if (eventName.indexOf("log") >= 0) {
|
if (eventName.indexOf("log") >= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// fs.appendFileSync(".embark/events.log", (new Error().stack) + "\n");
|
// fs.appendFileSync(".embark/events.log", (new Error().stack) + "\n");
|
||||||
if (!origin && origin !== "") {
|
if (!origin && origin !== "") {
|
||||||
const stack = new Error().stack;
|
const stack = new Error().stack;
|
||||||
|
@ -102,7 +102,7 @@ EmbarkEmitter.prototype.once = function(requestName, cb) {
|
||||||
};
|
};
|
||||||
|
|
||||||
EmbarkEmitter.prototype.setHandler = function(requestName, cb) {
|
EmbarkEmitter.prototype.setHandler = function(requestName, cb) {
|
||||||
log("SET HANDLER", requestName);
|
// log("SET HANDLER", requestName);
|
||||||
warnIfLegacy(requestName);
|
warnIfLegacy(requestName);
|
||||||
return _setHandler.call(this, requestName, cb);
|
return _setHandler.call(this, requestName, cb);
|
||||||
};
|
};
|
||||||
|
@ -113,13 +113,13 @@ 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);
|
// log("\nREQUEST", requestName);
|
||||||
warnIfLegacy(requestName);
|
warnIfLegacy(requestName);
|
||||||
if (this._events && !this._events['request:' + requestName]) {
|
if (this._events && !this._events['request:' + requestName]) {
|
||||||
this.debugLog.log({id: requestId, error: "no request listener for " + requestName})
|
|
||||||
log("NO REQUEST LISTENER", requestName);
|
|
||||||
|
|
||||||
if (debugEventsEnabled()) {
|
if (this.debugLog.isEnabled()) {
|
||||||
|
this.debugLog.log({ id: requestId, error: "no request listener for " + requestName, source: this.getOrigin()})
|
||||||
|
// 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,16 +145,18 @@ EmbarkEmitter.prototype.request2 = function() {
|
||||||
this._emit('request:' + requestName, ...other_args);
|
this._emit('request:' + requestName, ...other_args);
|
||||||
});
|
});
|
||||||
|
|
||||||
const ogStack = (new Error().stack);
|
let ogStack;
|
||||||
|
if (this.debugLog.isEnabled()) {
|
||||||
|
ogStack = (new Error().stack);
|
||||||
|
}
|
||||||
|
|
||||||
promise.catch((e) => {
|
promise.catch((e) => {
|
||||||
if (debugEventsEnabled()) {
|
if (this.debugLog.isEnabled()) {
|
||||||
console.dir(requestName);
|
console.dir(requestName);
|
||||||
console.dir(ogStack);
|
console.dir(ogStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.debugLog.log({id: requestId, error: "promise exception", stack: ogStack})
|
this.debugLog.log({id: requestId, error: "promise exception", outputs: ogStack, source: ogStack})
|
||||||
log("\n======== Exception ========", requestName, "\n " + ogStack + "\n==============");
|
|
||||||
return e;
|
return e;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -165,14 +167,18 @@ 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 requestId = this.debugLog.log({parent_id: this.logId, type: "old_request", name: requestName, inputs: other_args})
|
let origin;
|
||||||
|
if (this.debugLog.isEnabled) {
|
||||||
|
origin = this.getOrigin();
|
||||||
|
}
|
||||||
|
|
||||||
log("\nREQUEST(OLD)", requestName);
|
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]) {
|
||||||
this.debugLog.log({id: requestId, error: "no request listener for " + requestName})
|
if (this.debugLog.isEnabled()) {
|
||||||
log("NO REQUEST LISTENER", requestName);
|
this.debugLog.log({id: requestId, error: "no request listener for " + requestName})
|
||||||
if (debugEventsEnabled()) {
|
|
||||||
console.log("made request without listener: " + requestName);
|
console.log("made request without listener: " + requestName);
|
||||||
console.trace();
|
console.trace();
|
||||||
}
|
}
|
||||||
|
@ -197,17 +203,20 @@ EmbarkEmitter.prototype.request = function() {
|
||||||
|
|
||||||
// TODO: ensure that it's only possible to create 1 command handler
|
// TODO: ensure that it's only possible to create 1 command handler
|
||||||
EmbarkEmitter.prototype.setCommandHandler = function(requestName, cb) {
|
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 = ((new Error().stack).split("at ")[3]).trim();
|
// let origin = ((new Error().stack).split("at ")[3]).trim();
|
||||||
// origin = origin.split("(")[0].trim();
|
// origin = origin.split("(")[0].trim();
|
||||||
const origin = getOrigin();
|
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, source: origin});
|
||||||
log("== REQUEST RESPONSE", requestName, origin);
|
// log("== REQUEST RESPONSE", requestName, origin);
|
||||||
cb.call(this, ...arguments);
|
cb.call(this, ...arguments);
|
||||||
};
|
};
|
||||||
const listenerName = 'request:' + requestName;
|
const listenerName = 'request:' + requestName;
|
||||||
|
@ -237,7 +246,7 @@ 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);
|
// log("SET COMMAND HANDLER ONCE", requestName);
|
||||||
|
|
||||||
const listenerName = 'request:' + requestName;
|
const listenerName = 'request:' + requestName;
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,11 @@ class SuperLog {
|
||||||
this.logfile = "./structlog-" + (processIdentifier || "log") + ".json";
|
this.logfile = "./structlog-" + (processIdentifier || "log") + ".json";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: make this a flag depending on ENV var or constructor
|
||||||
|
isEnabled() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
addRecord(data) {
|
addRecord(data) {
|
||||||
// DB[data.id] = data
|
// DB[data.id] = data
|
||||||
fs.appendFileSync(this.logfile, "\n" + stringify(data, jsonFunctionReplacer, 0));
|
fs.appendFileSync(this.logfile, "\n" + stringify(data, jsonFunctionReplacer, 0));
|
||||||
|
@ -107,5 +112,3 @@ class SuperLog {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = SuperLog;
|
module.exports = SuperLog;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -227,14 +227,16 @@ Plugins.prototype.runActionsForEvent = function(eventName, args, cb, logId) {
|
||||||
return cb(null, args);
|
return cb(null, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.debugLog.log({parent_id: logId, type: "trigger_action", name: eventName, source: this.events.getOrigin(true), givenLogId: logId, plugins: actionPlugins, inputs: args});
|
let origin;
|
||||||
|
if (this.debugLog.isEnabled()) {
|
||||||
|
origin = this.events.getOrigin();
|
||||||
|
}
|
||||||
|
|
||||||
this.events.log("ACTION", eventName, "");
|
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;
|
||||||
|
|
||||||
self.events.log("== ACTION FOR " + eventName, plugin.name, pluginName);
|
|
||||||
let actionLogId = self.debugLog.log({module: pluginName, type: "action_run", name: (eventName + plugin.name), source: pluginName, inputs: current_args});
|
let actionLogId = self.debugLog.log({module: pluginName, type: "action_run", name: (eventName + plugin.name), source: pluginName, inputs: current_args});
|
||||||
|
|
||||||
if (typeof (args) === 'function') {
|
if (typeof (args) === 'function') {
|
||||||
|
|
Loading…
Reference in New Issue