[Owl-devel] Logging in OWL

Jose M. Duarte jose.m.duarte at gmail.com
Wed Aug 4 11:33:11 EDT 2010

Right thanks for the tip. I didn't know it was so simple.

So basically I've changed now all the calls to log4j loggers to calls to
common logging loggers as you explain below (adding jar to path was already
done, it's part of the uniprot japi).

I didn't manage yet to configure my application properly using common
logging configuration mechanisms (still using log4j config files and calls),
but anyway that can come later. The nice thing is that it works out of the
box even mixing the frameworks up!

BTW I also went through lots of trouble with jaligner logging (which is java
standard library logging) and especially with strange interactions between
it and log4j. Hopefully using commons logging will help to solve all that.



On 4 August 2010 15:17, Henning Stehr <stehr at molgen.mpg.de> wrote:

> Hi Jose,
> thanks for getting this started. Since we are just at the beginning
> with this, I would still pledge to consider using apache-logging
> instead of log4j. The thing is that if you use a specific logging
> framework in a library (such as owl) you are forcing the application
> that is using the library to use the same system. I had lots of
> troubles with JAligner because of this. The commons-logging library
> detects what the calling application is using and automatically passes
> the appropriate messages to it. The usage inside the library is very
> similar (though not identical) to log4j: (taken from
> http://commons.apache.org/logging/guide.html)
> 1. put commons-logging.jar in the classpath
> 2. add the following imports to a class that wants to use logging:
>       import org.apache.commons.logging.Log;
>       import org.apache.commons.logging.LogFactory;
> 3. Obtain the logger object:
>      private Log log = LogFactory.getLog(CLASS.class);
> 4. log messsages:
>    log.fatal(Object message);
>    log.error(Object message);
>    log.warn(Object message);
>    log.info(Object message);
>    log.debug(Object message);
>    log.trace(Object message);
> Now, I havn't used this extensively in practice so there may be
> reasons against using it that I don't see now. But it seems to me that
> there is a real benefit over using a particular implementation. If it
> works as promised it should only be necessary to change a few lines in
> the OWL classes that use logging and it should automatically work with
> any calling application, no matter what logging framework is being
> used there.
> You are right that it can probably be changed easily in the future, so
> there is no pressure to change now but I think it's worth considering
> at an early rather than late stage :)
> Cheers,
> Henning
> On Wed, Aug 4, 2010 at 2:45 PM, Jose M. Duarte <jose.m.duarte at gmail.com>
> wrote:
> > Yes for the program I'm developing (for bio vs crystal contacts
> > identification) I needed some proper logging. That's why I decided to
> give a
> > go to one of the logging frameworks.
> >
> > First I tried the logging from the standard java library but I was not
> very
> > happy with it. Then I went for log4j which as usual with apache things is
> a
> > lot better.
> >
> > Now I did see this apache commons logging thing, it seems like a meta
> > logging framework to use different frameworks underneath. But to be
> honest
> > it fell a bit like an overkill. I know in the long-run is probably not,
> but
> > at that point I couldn't be bothered. Anyway the implementation change
> > shouldn't be very difficult if we want to do it. The real difficult thing
> > with logging is the logging itself! what messages to write, which level
> to
> > put them in etc. After some experience using it I've realised it really
> is
> > not easy!
> >
> > Anyway I definitely recommend it, the basic usage really is very simple,
> all
> > you need is to declare this constant in your class:
> >
> > private static final Logger LOGGER =
> Logger.getLogger(UniprotEntry.class);
> >
> > and then you use it like:
> >
> > LOGGER.error("An error happened");
> > LOGGER.fatal("A real bad error");
> >
> > Jose
> >
> >
> > On 4 August 2010 14:38, Henning Stehr <stehr at molgen.mpg.de> wrote:
> >>
> >> Hi Jose,
> >>
> >> I just looked through the history of OWL. The package is really
> >> getting more and more powerful. Great work. I saw that you also
> >> started to use logging which I think is really a good idea. I'm not
> >> sure which implementation you used but may I suggest to use the apache
> >> commons-logging? It looks almost like log4j but it is in fact just an
> >> adapter that can be used with different logging implementations in the
> >> calling application. This way we don't restrict ourselves to any of
> >> log4j/java logging/etc...
> >>
> >> Cheers,
> >> Henning
> >>
> >> _______________________________________________
> >> Owl-devel mailing list
> >> Owl-devel at bioinformatics.org
> >> http://www.bioinformatics.org/mailman/listinfo/owl-devel
> >
> >
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.bioinformatics.org/pipermail/owl-devel/attachments/20100804/dbaa6165/attachment-0001.html>

More information about the Owl-devel mailing list