NetBeans: Generating Java Util Logger

add to del.icio.us with other 0 users
Java Util Logger has enabled us to ship application without having dependency on any external JARs or APIs for logging purpose. After starting to use it I felt the necessity of a Logger creation tool which will create and initialize a logger for me instead of me either writing it or Copy-Pasting it for every file or worse every class. Also using a tool will enable me to maintain a coherence of naming and initialization of loggers across a project.

With the release of Java Source API with NetBeans 6.1Beta I finally got the chance to write such a tool for myself :). In sequence with my toString() generator module I started this module as well. You can download the NBM file and install it as it is free and open source. How-to of this tool is as follows.

Basically what I needed for it can be stated in 3 steps -
  1. Parse/read the Java File
  2. Find declared classes
  3. Check if Logger exists if not create it and add utility methods.
With the new Java Source API and Java Compiler Tree API it is nothing more than simple tree traversing for the purpose. You can have a peek at the implementation in the addLogger method in the source file (after opening the file 'Find' might be useful). One will find these NetBeans Wiki pages being helpful.

Share/Save/Bookmark

2 comments:

  1. it seems very helpful tool, so we can let our tool handle or add logger related function with in the source code.
    thanks for nice work

    ReplyDelete

Search