[Biojava-dev] How are we supposed to log errors?

Jose Manuel Duarte jose.duarte at psi.ch
Thu Aug 28 14:40:17 UTC 2014


FYI

I've just merged a pull request that introduces slf4j officially in all 
biojava modules. I've also bound it to log4j2 in the runtime scope 
(which covers also tests). That's only for internal biojava use. Then 
the final user is still free to choose what framework to use and how to 
configure it.

As a first test case I've converted the logger of PDBFileParser to slf4j 
and all seems to be working nicely. Now there's a lot of logging still 
left to do. You just need to construct one at the top of your class:

  private static final Logger logger = 
LoggerFactory.getLogger(MyClassName.class);

and then log away with:

  logger.warn("This is dangerous, something might not be right but we 
know how to deal with it");
  logger.info("This is informative");
  logger.debug("This is too informative");

I have also added config files for log4j2 to the structure module (but 
not to any of the other modules). As default levels I've set: "warn" for 
running and "info" for testing.

Happy logging!

Jose



On 27/05/14 05:33, Andreas Prlic wrote:
> ok, slf4j has been suggested here before, so I take this as a clear vote
> towards starting to use that. Anybody opposed to this?
>
> We have an empty wiki page for this topic already
> http://www.biojava.org/wiki/BioJava3_logging
>
> Anybody willing to add some docu and recommendations for how to use it?
>
> Andreas
>
>
>
>
> On Mon, May 26, 2014 at 11:35 AM, Paolo Bizzarri <pibizza at gmail.com> wrote:
>
>> My understanding is that the basic Java logging is typically perceived as
>> too limited.
>>
>> I think it is really important to keep the dependecies of a package to a
>> bare minimum.
>>
>> However, logging is such a fundamental feature for a library that I would
>> pay the price of a extra dependecy for a good package for logging.
>>
>> slf4j could be a good choice.
>>
>> Regards
>>
>> Paolo
>>
>>
>> On Mon, May 26, 2014 at 4:45 PM, Andreas Prlic <andreas at sdsc.edu> wrote:
>>
>>> I am always reluctant to add additional jar dependencies to the project.
>>> Is
>>> the basic logging API that is part of Java sufficient?
>>>
>>> Andreas
>>>
>>>
>>>
>>>
>>> On Mon, May 26, 2014 at 2:37 AM, LAW Andy <andy.law at roslin.ed.ac.uk>
>>> wrote:
>>>
>>>> If I had a vote, then SLF4J (www.slf4j.org) would get it.
>>>>
>>>> Later,
>>>>
>>>> Andy
>>>>
>>>>
>>>> On 26 May 2014, at 09:43, Spencer Bliven <sbliven at ucsd.edu> wrote:
>>>>
>>>>> I wouldn't be opposed to using one of the standard logging apis in
>>>> biojava
>>>>> (apache log4j, for instance). The downside of this is that users would
>>>> have
>>>>> to include one of the implementation jars in their classpath, and
>>> failure
>>>>> to do so leads to fairly opaque error messages.
>>>>>
>>>>> -Spencer
>>>>>
>>>>>
>>>>> On Mon, May 26, 2014 at 8:21 AM, Paolo Bizzarri <pibizza at gmail.com>
>>>> wrote:
>>>>>> Hi Andreas,
>>>>>>
>>>>>> it depends on the use case of biojava, I think - something that I
>>> don't
>>>>>> know very well at the moment.
>>>>>>
>>>>>> If biojava is going to be used for short running processes with a
>>>> limited
>>>>>> output, you can clearly rely on the standard error for logging errors
>>>> and
>>>>>> exceptions.
>>>>>>
>>>>>> On the other side, if your process is a long running one, potentially
>>>>>> producing lots of output, you do not want to miss any error just
>>> because
>>>>>> things scroll up, or because you forgot to redirect your standard
>>> error
>>>> to
>>>>>> a file.
>>>>>>
>>>>>> I could provide a patch some of the System.out invocations to a
>>> logger,
>>>> so
>>>>>> that we can see how the code will work.
>>>>>>
>>>>>> What do you think?
>>>>>>
>>>>>> Regards.
>>>>>>
>>>>>> Paolo
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Mon, May 26, 2014 at 7:17 AM, Andreas Prlic <andreas at sdsc.edu>
>>>> wrote:
>>>>>>> Hi Paolo,
>>>>>>>
>>>>>>> We don't have strict standards how to log throughout the code base.
>>> The
>>>>>>> topic has come up on and off, but so far we have not agreed on any
>>>>>>> convention.
>>>>>>>
>>>>>>> Andreas
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Sun, May 25, 2014 at 12:43 AM, Paolo Bizzarri <pibizza at gmail.com
>>>>>>> wrote:
>>>>>>>
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> I am looking at the code inside
>>>>>>>> org.biojava.bio.structure.align.util.AtomCache.
>>>>>>>>
>>>>>>>> I see that many times the code prints the stack trace on the
>>> standard
>>>>>>>> error.
>>>>>>>>
>>>>>>>> I understand that in other parts of the code we use to a standard
>>>> logger
>>>>>>>> instead.
>>>>>>>>
>>>>>>>> Which of the two is the expected approach?
>>>>>>>>
>>>>>>>> Regards.
>>>>>>>>
>>>>>>>> Paolo
>>>>>>>> _______________________________________________
>>>>>>>> biojava-dev mailing list
>>>>>>>> biojava-dev at lists.open-bio.org
>>>>>>>> http://lists.open-bio.org/mailman/listinfo/biojava-dev
>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>> _______________________________________________
>>>>>> biojava-dev mailing list
>>>>>> biojava-dev at lists.open-bio.org
>>>>>> http://lists.open-bio.org/mailman/listinfo/biojava-dev
>>>>>>
>>>>> _______________________________________________
>>>>> biojava-dev mailing list
>>>>> biojava-dev at lists.open-bio.org
>>>>> http://lists.open-bio.org/mailman/listinfo/biojava-dev
>>>>
>>>> --
>>>> The University of Edinburgh is a charitable body, registered in
>>>> Scotland, with registration number SC005336.
>>>>
>>>>
>>>> _______________________________________________
>>>> biojava-dev mailing list
>>>> biojava-dev at lists.open-bio.org
>>>> http://lists.open-bio.org/mailman/listinfo/biojava-dev
>>>>
>>> _______________________________________________
>>> biojava-dev mailing list
>>> biojava-dev at lists.open-bio.org
>>> http://lists.open-bio.org/mailman/listinfo/biojava-dev
>>>
>>
> _______________________________________________
> biojava-dev mailing list
> biojava-dev at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/biojava-dev



More information about the biojava-dev mailing list