Catch / Listen to function's execution

一曲冷凌霜 提交于 2019-12-14 01:18:17

问题


I want to add to all functions in module logger. I want to log "start" time of the function and "end" time. So that's way I can get performance time of every function (sync functions).

But I can't get how to make it work.. =( I don't want to rewrite functions in some dynamic way - I want to debug them in the future..So need to keep original code - I need to find some way to wrap every function...

Lets take a look some example:

module.exports = {
   someVar: "12345string",

   operation1: function(){
      alert("operation1");
   },

   operation2: function(){
      alert("operation2");
   }
};

Once module's function executed, we need to run some "pre" and "post" execution script...

How can I do this? Help please... I have a lot of modules and functions... =(


回答1:


OK! So I used meld package and that's works great!

As Jim Garrison said in the comment - every AOP package/lib can help to solve that problem.

I found meld as very simple & clear.



来源:https://stackoverflow.com/questions/38950120/catch-listen-to-functions-execution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!