0

We have a web application which sometimes (quite rarely, several times a day) gives an error in production. It is deployed on Tomcat, uses Spring+Hibernate, the error is caused by a Hibernate exception which is hard to understand without actually logging the parameters passed to the method of the Hibernate class. It is not possible to replace the Hibernate library with a modified version which logs the parameters, and spring-aop cannot be used since the "beans" are not managed. I have seen an example of byte code instrumentation using javassist, on http://today.java.net/pub/a/today/2008/04/24/add-logging-at-class-load-time-with-instrumentation.html, however trying to run it under tomcat, the instrumented code does not seem to run, probably due to classloader problems which I currently don't understand.

What I am asking then, is this: does anyone know of a more or less simple way to instrument the byte code under tomcat for such a task as logging the parameters of methods in external libraries? is there some further insight you may give on this problem?

John Donn
  • 1,718
  • 2
  • 19
  • 45

2 Answers2

2

Have a look at BTrace.

It will allow you to log calls to other classes/functions without slowing down the main application.

mindas
  • 26,463
  • 15
  • 97
  • 154
  • this just looks so powerful.. though didn't actually solve my problem, it might have had if the webapp would run on Java 6 and not on Java 5 :) – John Donn Jan 22 '12 at 18:44
1

You could (temporarily) enable JDWP on the production Tomcat, attach a debugger, and place a breakpoint on the offending code. But I'd recommend avoiding doing that on the actual production machine -- better to clone the production environment to another machine that you can tinker with.

Community
  • 1
  • 1
Daniel Pryden
  • 59,486
  • 16
  • 97
  • 135
  • You could take a look at YouDebug (http://youdebug.kenai.com/) which allows you to utilize the JDI (debugging interface) without actually setting up the IDE with the external libraries sources and then stopping the JVM upon breakpoint hit. Instead a handler code is executed when a breakpoint is hit and you can inspect eg. local variables etc. This might even be plausible for use on production server even though the performance hit would surely be noticable for the time you are connected with YouDebug, – JB- Jun 22 '12 at 20:23