Tuesday, 15 February 2011

java - Exclude an exception from log -



java - Exclude an exception from log -

how can exclude specific exception beingness logged in aspectj?

we're using spring security, we've have implementation of userdetailsservice. when user enters username not exist, spring throws org.springframework.security.core.userdetails.usernamenotfoundexception. want exclude specific exception log, not class thrown (implementation of userdetailsservice).

for illustration in next log, want first line (entering...userdetailsserviceimpl) , not errors follow.

22 jun 2014 14:20:35 info loggingaspect - entering: ...userdetailsserviceimpl method name: loaduserbyusername method arguments : [***] 22 jun 2014 14:20:42 error loggingaspect - unhandled exception caught: ...service.userdetailsserviceimpl loaduserbyusername org.springframework.security.core.userdetails.usernamenotfoundexception: user loginname: *** doesnt exist @ ...userdetailsserviceimpl.loaduserbyusername(userdetailsserviceimpl.java:30) ...

is there way spring aop?

edit: have in loggingaspect:

@afterthrowing(pointcut = "execution(* ..*.*(..)) && !methodsexcludedfromlog()", throwing = "exp") public void afterthrowing(joinpoint joinpoint, throwable exp) { ... }

i need somehow alter throwing exclude spring exception, i'm not sure how that.

edit 2: suggested in comments, tried adding filter in log4j, doesn't seem work, , exception doesn't filtered out. know problem might be?

<appender name="consoleappender" class="org.apache.log4j.consoleappender"> <layout class="org.apache.log4j.patternlayout"> <param name="conversionpattern" value="%d{dd mmm yyyy hh:mm:ss} %5p %c{1} - %m%n" /> </layout> </appender> <appender name="fileappender" class="org.apache.log4j.rollingfileappender"> <param name="append" value="false" /> <param name="file" value="${catalina.home}/logs/myapp.log" /> <layout class="org.apache.log4j.patternlayout"> <param name="conversionpattern" value="%d{absolute} %-5p [%c{1}] %m%n" /> </layout> <filter class="org.apache.log4j.filter.expressionfilter"> <param name="expression" value="exception ~= org.springframework.security.core.userdetails.usernamenotfoundexception" /> <param name="acceptonmatch" value="false"/> </filter> </appender> <root> <level value="info" /> <appender-ref ref="consoleappender" /> <appender-ref ref="fileappender" /> </root>

thanks.

as discussed in comments, can use

class="lang-java prettyprint-override">{ if (e instanceof usernamenotfoundexception) return; // log exception }

at origin of advice. there no syntactic way in either aspectj or spring aop somehow utilize jokers or boolean expressions in "throwing" part. there have alternative either capture exceptions or implicitly narrow downwards selection 1 specific type (and subtypes) binding thrown exception typed variable. if think it, how should bind object variable having multiple types?

whether or not, right answer. cannot alter aspectj syntax , semantics now. :-)

java spring aspectj spring-aop

No comments:

Post a Comment