记录方法的名称和参数 [英] Logging a methods's name and parameters

查看:86
本文介绍了记录方法的名称和参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在与一家公司合作,在当前的项目中,该公司必须实施一项编写大量代码跟踪日志记录(JAVA)的策略,该策略已经完成了一段时间。

I've been working with a company that, in this current project, has to implement a policy of writing lots of trace logging in code (JAVA) that has already been completed for some time.

我试图避免改变每一个方法只是为了写一个logger.log('期望值'),就像所有这些一样。这太适得其反了。

I am trying to avoid changing every single method just to write a logger.log('desired values') like code line on all of them. it's just too counter-productive.

是否有一种通用的方法来记录方法名称,它收到的参数,而不会改变太多的代码?我一直在研究注释和类似的东西,但是有很多方法有不同的参数,所以我无法找到一个好的解决方案。

Is there a generic way to log a method name, the parameters that it received, without changing much of the code? I've been researching annotations and stuff like that but there are a lot of methods with different parameters so i haven't been able to come up with a good solution.

编辑1:
该项目正在eclipse上开发。我正在使用Liferay和JBoss对门户进行一些更改。

EDIT 1: The project is being developed on eclipse. I'm doing some changes in a portal using Liferay and JBoss.

编辑2:
我已经按照给我的解决方案并使用了拦截器。我必须对现有方法进行的唯一更改是为它们添加注释,这是完全可以接受的。
欲了解更多信息,请访问以下链接:
http ://docs.oracle.com/javaee/6/tutorial/doc/gkeed.html

推荐答案

你可以使用拦截器 http://docs.oracle.com/javaee/6/ tutorial / doc / gkeed.html 在没有任何代码更改的情况下拦截对公共方法的调用,但是不可能将此技术用于非公共方法。

You can use interceptors http://docs.oracle.com/javaee/6/tutorial/doc/gkeed.html to intercept calls to public methods without any code changes, it is impossible to use this technique with non-public methods though.

这篇关于记录方法的名称和参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆