How to automatically log the entry/exit of methods in Java?

I suggest the use of Aspect Oriented Programming. For example, using the AspectJ compiler (which can be integrated to Eclipse, Emacs and others IDEs), you can create a piece of code like this one: aspect AspectExample { before() : execution(* Point.*(..)) { logger.entering(thisJoinPointStaticPart.getSignature().getName(), thisJoinPointStaticPart.getSignature().getDeclaringType() ); } after() : execution(* Point.*(..)) { logger.exiting(thisJoinPointStaticPart.getSignature().getName() , thisJoinPointStaticPart.getSignature().getDeclaringType() ); … Read more

Tomcat logging confusion

If I’m understanding correctly you end up with a logging properties that looks like: java.util.logging.ConsoleHandler.level = FINER org.apache.catalina.realm.level = FINER The Java Logging Overview section 1.1 states: Applications make logging calls on Logger objects. Loggers are organized in a hierarchical namespace and child Loggers may inherit some logging properties from their parents in the namespace. … Read more

java.util.logging: how to suppress date line

From Java SE 7 there is a new system property: java.util.logging.SimpleFormatter.format. The same property is also configurable on the java.util.logging properties file (logging.properties). If you are an Eclipse user, and you are annoyed by the double line message in the console output, you could change the jre logging.properties file (JDK_HOME/jre/lib/logging.properties) in this way: java.util.logging.SimpleFormatter.format=%4$s: %5$s … Read more

JUL to SLF4J Bridge

You need to call SLF4JBridgeHandler.install(). You also need to enable all log levels at the root logger (reason in excerpt below) in java.util.logging and remove the default console appender. This handler will redirect jul logging to SLF4J. However, only logs enabled in j.u.l. will be redirected. For example, if a log statement invoking a j.u.l. … Read more

Custom java.util.logging Handler in tomcat

For the Tomcat-wide custom logging you need to inject your class into the Tomcat bootstrap ClassLoader. Thus jar with custom Handler and required dependencies have to be put into the startup script CLASSPATH. I’d advice to a add custom script at $CATALINA_BASE/bin/setenv.sh, i.e. #!/bin/sh CLASSPATH=”$CATALINA_BASE/bin/myhandler.jar” or you can collect required jars dynamically as script variables … Read more