捕捉/监听函数的执行 [英] Catch / Listen to function's execution
问题描述
我想添加到模块记录器中的所有功能.我想记录该功能的开始"时间和结束"时间.这样一来,我可以获得每个函数(同步函数)的执行时间.
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...
让我们看一些例子:
module.exports = {
someVar: "12345string",
operation1: function(){
alert("operation1");
},
operation2: function(){
alert("operation2");
}
};
一旦模块的功能被执行,我们需要运行一些"pre"和"post"执行脚本...
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... =(
推荐答案
好!因此,我使用了 meld 软件包,效果很好!
OK! So I used meld package and that's works great!
正如吉姆·加里森(Jim Garrison)在评论中所说-每个AOP软件包/库都可以帮助解决该问题.
As Jim Garrison said in the comment - every AOP package/lib can help to solve that problem.
我发现Meld非常简单&清除.
I found meld as very simple & clear.
这篇关于捕捉/监听函数的执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!