[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] Logging enabled check idea
|
Hey,
thanks for the reply! I will check if that works. Maybe we can check the string creation as follows:
public class MyApp {
// Define a static logger variable so that it references the
// Logger instance named "MyApp".
static Logger logger = Logger.getLogger(MyApp.class);
public static void main(String[] args) {
int i = 0;
// Set up a simple configuration that logs on the console.
BasicConfigurator.configure();
logger.info("Entering application." + (i++));
Bar bar = new Bar();
bar.doIt();
logger.info("Exiting application." + (i++));
System.out.println( "i = " i );
}
}
If i is 2, then the string was created, if it is 0, it works perfectly, right?
regards,
Wim
2006/6/6, Kaare Nilsen <kaare.nilsen@xxxxxxxxx>:
Would this do the trick ?
It will for sure hit regarding to the pointcut, but not quite shure if
it will actually save the construction of the string.
@Aspect
public class LoggingAspect {
@Around("call (*
Logger.debug(..)) && target(log) &&
!within(LoggingAspect)")
public void isDebugEnabled(ProceedingJoinPoint thisJoinPoint,
Logger log) throws Throwable {
if (log.isDebugEnabled
()) {
thisJoinPoint.proceed();
}
}
}
/Kaare Nilsen
On 06/06/06, Wim Deblauwe <wim.deblauwe@xxxxxxxxx> wrote:
> Hi,
>
> I just had this idea for the use of aspectj, but I don't know if it is
> possible:
>
> Most of you know that they can check if logging is enabled before putting
> the log statement in their code, however, very few do this because it
> clutters the code. Would it be possible to define an aspect that adds all
> those checks in there (with log4j and/or commons-logging)?
>
> Just an idea if someone has some time to spare :)
>
> regards,
>
> Wim
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
>
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users