Logging 在EclipseRCP项目中为多个插件创建方面
我正在开发一个包含多个插件的rcp项目,并使用AJDT aspectJ在应用程序中记录日志。我在每个插件中创建了两个方面,一个用于信息日志记录,一个用于异常日志记录。对于基本插件,这个方面可以正常工作,但对于其他插件,它不起作用 我对上述实施有一些疑问:Logging 在EclipseRCP项目中为多个插件创建方面,logging,aspectj,ajdt,Logging,Aspectj,Ajdt,我正在开发一个包含多个插件的rcp项目,并使用AJDT aspectJ在应用程序中记录日志。我在每个插件中创建了两个方面,一个用于信息日志记录,一个用于异常日志记录。对于基本插件,这个方面可以正常工作,但对于其他插件,它不起作用 我对上述实施有一些疑问: 这是为每个插件定义一个方面的正确方法,还是我们可以为所有插件创建一个方面 如果不同插件中的包名相同,那么在为每个插件创建seprate方面时会出现问题 我尝试为普通日志和异常日志创建一个方面,但不适合我。附加正常方面和异常方面的示例 有没有办法
Caused by: org.aspectj.lang.NoAspectBoundException: com_tsystems_rvs_client_gui_user_RvsUserAspect
at com.tsystems.rvs.client.gui.user.RvsUserAspect.aspectOf(RvsUserAspect.aj:1)
at com.tsystems.rvs.client.gui.user.RvsUserAspect.<clinit>(RvsUserAspect.aj:27)
插件中日志异常的代码
public aspect RvsFrameworkExceptionAspect {
public pointcut scope(): within(com.tsystems.rvs..*);
private Map<Throwable, String> loggedThrowables = new WeakHashMap<Throwable, String>();
after() throwing(Throwable t): scope() {
logThrowable(t, thisJoinPointStaticPart,
thisEnclosingJoinPointStaticPart);
}
before (Throwable t): handler(Exception+) && args(t) && scope() {
logThrowable(t, thisJoinPointStaticPart,
thisEnclosingJoinPointStaticPart);
}
protected synchronized void logThrowable(Throwable t, StaticPart location,
StaticPart enclosing) {
if (!loggedThrowables.containsKey(t)) {
loggedThrowables.put(t, null);
Signature signature = location.getSignature();
String source = signature.getDeclaringTypeName() + ":"
+ (enclosing.getSourceLocation().getLine());
LoggerMode.getInstance().logError(" " + source + " - " + t.toString(), t);
}
}
公共方面RvsFrameworkExceptionAspect{
公共切入点范围():在(com.tsystems.rvs..*)内;
私有映射loggedThrowables=new WeakHashMap();
after()抛出(Throwable t):范围(){
logThrowable(t,此连接点静态部分,
此封闭接合点(静态部件);
}
before(Throwable t):处理程序(异常+&&args(t)&&scope(){
logThrowable(t,此连接点静态部分,
此封闭接合点(静态部件);
}
受保护的同步void logThrowable(Throwable t、StaticPart位置、,
静态(部分封闭){
如果(!loggedThrowables.containsKey(t)){
loggedThrowables.put(t,null);
签名签名=location.getSignature();
字符串源=签名。getDeclaringTypeName()+“:”
+(封闭.getSourceLocation().getLine());
LoggerMode.getInstance().logError(“+source+”-“+t.toString(),t”);
}
}
}
请帮助我在实现中犯了什么错误。可能您在
rvsframeworkexceptionspect
中的切入点只是建议您要排除的类。具体来说,
在(com.tsystems.rvs..*)中
将匹配
com.tsystems.rvs.client.gui.user.rvsuserspect
i、 你似乎在建议另一个方面。试着对你想要截取的内容更具体一点
编辑关于评论中的其他问题:
如果所有方面的类名都以“方面”结尾,则可以尝试此方法:
在(com.tsystems.rvs..*)&&!在(*…*方面)
否则,您可以排除单个方面类,或者只包含较少的非方面类,只要在您的情况下更简单。通常,在不了解完整代码基础的情况下,很难提供有用的提示,因此请理解,我可能无法达到您希望的目标。;-) 你能给我举个例子吗。
public aspect RvsFrameworkExceptionAspect {
public pointcut scope(): within(com.tsystems.rvs..*);
private Map<Throwable, String> loggedThrowables = new WeakHashMap<Throwable, String>();
after() throwing(Throwable t): scope() {
logThrowable(t, thisJoinPointStaticPart,
thisEnclosingJoinPointStaticPart);
}
before (Throwable t): handler(Exception+) && args(t) && scope() {
logThrowable(t, thisJoinPointStaticPart,
thisEnclosingJoinPointStaticPart);
}
protected synchronized void logThrowable(Throwable t, StaticPart location,
StaticPart enclosing) {
if (!loggedThrowables.containsKey(t)) {
loggedThrowables.put(t, null);
Signature signature = location.getSignature();
String source = signature.getDeclaringTypeName() + ":"
+ (enclosing.getSourceLocation().getLine());
LoggerMode.getInstance().logError(" " + source + " - " + t.toString(), t);
}
}