6/14/2006

Why We Need to Test with Logging Level FINEST

Does your team run a full test cycle with logging level FINEST? Probably not. From my experience in several projects, we are happy if all tests passed with default logging level. But there are good reasons why we need to include logging level FINEST in part of our testing:

  • Expose application erros such as NullPointerException, ClassCastException, etc. They are buried deep in code blocks that are only executed with logging level FINE, FINER, or FINEST. In production environment, customers or field engineers turn on FINE logging level for userful info, not these nasty exceptions. Catch them early in testing. For example,
    if(logger.isLoggable(Level.FINE)) {
    logger.log(Level.FINE, user.toString());
    }
  • Make sure sensitive data, such as password and account numbers are not logged anywhere at any levels.

  • Expose any thread deadlocks caused by more frequent logging. Several commonly used classes are heavily synchronized, such as java.util.Logger, java.lang.ClassLoader, java.util.ResourceBundle, java.io.PrintStream, etc. In a multi-threaded application, it's easy to get into thread deadlocks, especially when java.util.Logger is invoked more frequently at FINEST level. For example,

    Thread A holds a lock on its context classloader to load a class, and also tries to acquire a lock on logger to log some FINE messages : Loading class with Class.forName(classname).

    Thread B holds a lock on the same logger to do some logging, which invokes ResourceBundle.loadBundle(), which in turn invokes ClassLoader.loadClass(), which requires a lock on the class loader. Therefore, thread A is holding a lock on context classloader and waiting on a lock on logger; thread B is holding a lock on logger and waiting on a lock on the context classloader, hence the deadlock.
To fix the above bug, don't call any logging-related methods inside synchronized methods of a classloader.

7 comments:

Anonymous said...

Who knows where to download XRumer 5.0 Palladium?
Help, please. All recommend this program to effectively advertise on the Internet, this is the best program!

Anna said...

Great and Useful Article.

Online Java Course

Java Online Training

Java Course Online

J2EE training

online J2EE training

Best Recommended books for Spring framework

Java Interview Questions












Java Training Institutes in Chennai

Java Training in Chennai

J2EE Training in Chennai

java j2ee training institutes in chennai

Love Kpop said...

I like to get up early to go out and breathe fresh air. I feel that it is good for health and a good habit
http://19216811ll.com

keanna said...

There are such a significant number of explanations behind developing python programming language as it can create following project for the sake of single programming language

For More Info:- Python Training Course in Gurgaon

Repairtech Solutions said...

Very good info. Lucky me I discovered your website by accident (stumbleupon). I have book marked it for later! onsite mobile repair bangalore This blog was... how do I say it? Relevant!! Finally I have found something that helped me. Thank you! asus display repair bangalore Everything is very open with a really clear description of the challenges. It was really informative. Your site is useful. Thank you for sharing! huawei display repair bangalore

Repairtech Solutions said...

You ought to be a part of a contest for one of the highest quality sites online. I most certainly will recommend this website! online laptop repair center bangalore A fascinating discussion is definitely worth comment. I believe that you should write more about this subject matter, it might not be a taboo matter but usually people don't talk about these issues. To the next! Many thanks!! dell repair center bangalore

Repairtech Solutions said...

Howdy! I just want to offer you a huge thumbs up for your great information you have right here on this post. I'll be returning to your site for more soon. macbook repair center bangalore When I originally commented I seem to have clicked the -Notify me when new comments are added- checkbox and from now on whenever a comment is added I recieve four emails with the same comment. There has to be an easy method you can remove me from that service? Many thanks! acer repair center bangalore