[Biojava-l] Logging in BJ3

Neil Benn benn at mpi-cbg.de
Tue Oct 21 09:00:44 UTC 2008


Hello,

          I'm not sure if I should comment as I have no time to 
contribute LOC but I thought I may as well ;).

Mark Schreiber wrote:
> Hi -
>
> I would like to strongly advocate the liberal and extensive use of
> Logging in BioJava3.  The lack of this plagued us (me at least) during
> bug fixes in previous versions of BioJava.  The default Java logging
> API is very flexible and easily meets our needs. It's also not too
> much effort for developers to put in place (you know you use
> System.println() all over the place anyway).
>   
Hmm, that is true but for total completeness you can use 
commons-logging, that is very easy to use and much more flexible as it 
can encapsulate other logging mechanisms (including JDK1.4 logging 
framework).  To use it you simply declare a new logger as follows:

private static final Log logger = LogFactory.getLog(<Insert classname 
here>);

The rest of it works pretty much the same as below- if you dovetail 
commons-logging with log4j then you'll cover the most common case of 
logging used in other frameworks - the config files to setup log4j (XML 
and preperties fiels) are well documented all over the web.
> <snip>
>
> I know from experience we will definitely get the most value from this
> in the IO parsers and ThingBuilders.
>
> Any thoughts?
>   
+1
> - Mark
>
>
>
>     private Logger logger = Logger.getLogger("org.biojava.MyClass");
>
>     public Object generateObject(String argument){
>          logger.entering(""+getClass(), "generateObject", argument);
>
>          //expensive logging operation
>          if (logger.isLoggable( Level.CONFIG )) {
>             logger.config("DB config: "+ getDBConfigInfo());
>          }
>
>          Object obj = null;
>          try{
>
>             //do some stuff
>             logger.fine("doing stuff");
>             obj = new Object();
>
>          }catch(Exception ex){
>              logger.severe("Failed to do stuff");
>              logger.throwing(""+getClass(), "generateObject", ex);
>          }
>
>          logger.exiting(""+getClass(), "generateObject", obj);
>          return obj;
>     }
> _______________________________________________
> Biojava-l mailing list  -  Biojava-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/biojava-l
>   




More information about the Biojava-l mailing list