Skip to content

Instantly share code, notes, and snippets.

@vinifig
Created April 25, 2019 21:21
Show Gist options
  • Save vinifig/fa0e3bb433d00f79b80d36491cfe5ce2 to your computer and use it in GitHub Desktop.
Save vinifig/fa0e3bb433d00f79b80d36491cfe5ce2 to your computer and use it in GitHub Desktop.
log system prototype based on aspect oriented programming
function fxabc (...params) { return params }
let fxabcArrow = (...params) => { throw new Error(JSON.stringify(params)) }
let runnerOperations = {
logger: (id) =>
(message) =>
console.log(`${id} - ${message}`),
run (fx, ...params) {
let logger = this.logger(Date.now());
logger(`running ${fx.name} with parameters: [${params.join(", ")}]`);
try {
let response = fx(...params);
logger(`response: ${response}`);
} catch(e) {
logger(`error: ${e}`);
}
}
}
runnerOperations.run(fxabc, 1, 2, 3, 4);
runnerOperations.run(fxabcArrow, 1, 2, 3, 4, {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment