Re: Change logging level for Logger.throwing
Stefan Istrate wrote:
Is there any possibility to change the logging level used by
Logger.throwing from FINER to SEVERE?
Not really.
The FINER is hard coded in that method.
If you need a practical solution and are willing to
do what it takes to solve the problem, then you
can use AspectJ.
Just compile all your code together with the
following:
import java.lang.reflect.*;
import java.util.logging.*;
import org.aspectj.lang.*;
import org.aspectj.lang.annotation.*;
@Aspect
public class Hack {
@Pointcut("call(void
java.util.logging.Logger.throwing(String,String,Throwable))")
public void changeLevel() {}
@Around(value = "changeLevel()")
public void makeSevere(ProceedingJoinPoint pjp) {
Logger log = (Logger)pjp.getTarget();
Object[] args = pjp.getArgs();
LogRecord lr = new LogRecord(Level.SEVERE, "THROW");
lr.setSourceClassName((String)args[0]);
lr.setSourceMethodName((String)args[1]);
lr.setThrown((Throwable)args[2]);
log.log(lr);
}
}
and the resulting code will do what you want:
C:\>javac TLog.java
C:\>java TLog
11-04-2009 22:34:25 TLog main
FINER: THROW
java.lang.Exception: Ooops
at TLog.main(TLog.java:9)
C:\>ajc -source 1.5 TLog.java Hack.aj
C:\>java TLog
11-04-2009 22:34:35 TLog main
SEVERE: THROW
java.lang.Exception: Ooops
at TLog.main(TLog.java:9)
Arne