Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] Proper usage of log4j

You can’t really match this use with the static pointcuts available to declare error. Under the covers this is just a call to StringBuilder.append with a Throwable instance, but there’s no way to say the static type of the argument is a Throwable. Another strategy would be to flag an error if you log without logging the exception inside a handler, but you can’t say lexically within handler in an AspectJ pointcut, and you can’t use cflow for declare error/warning.

 

However, what you might want to do instead is to ADD the stack trace in advice:

 

after(Logger logger, Throwable t) returning: (call(* Category.*(..)) || call(* Logger.*(..))) && args(*) && cflow(handler(t)) && target(logger) {

   logger.error(“Cause”, t);

}

 

This could be refined to call the right log level and to only trigger once per handler (e.g., using a percflow aspect).

 


From: aspectj-users-bounces@xxxxxxxxxxx [mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Andrej Amster
Sent: Thursday, May 10, 2007 11:04 AM
To: aspectj-users@xxxxxxxxxxx
Subject: [aspectj-users] Proper usage of log4j

 

Hello,

I have declaration in my class using org.apache.log4j.Logger:
    private static final Logger log = Logger.getLogger(PrihlaskaReportBean.class);

And i would like to ask for hint about how to formulate declare error pointcut, which could capture following:

log.error("some message" + e);

I want to capture this logging usage, because the "+ e" calls e.toString(), which causes to print only the message without stacktrace(stacktrace i want to see always).

Proper usage would be(which i want to enforce):

log.error("some message", e);

Best regards,

Andrej J.
AspectJ/AJDT enthusiast


Back to the top