Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Unit testing the log statements

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jeff,
In "Agile Java" logging is covered - notably tests making sure the log statements are
as intended...
I loved what I saw - however, in practice, I found people tweaking/adding logging statements to
get better insight...
This was far too dynamic (in my humble opinion)...
I have always wondered if testing for logging really works (and do people keep up the tests?)

--- regards atul
 
author
Posts: 799
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Atul,

More often than not, logging is an ad hoc exercise, and I suspect most teams over-log. Of course, when you have a sticky production problem, it always seems like you've under-logged.

My other concern about logging is that I've seen enough unfortunate cases where the logging code itself had defects, and that sort of thing is rarely tested on any level (automated or manual, unit or integrated).

Everyone I've seen (myself included) insert logging statements without tests, and most of the time that's probably ok. I still find a need to test some of the more interesting and/or critical areas of the system where I've inserted logging, particularly when there's a bit of logic involved. But yeah, that's fairly rare for me even.

Jeff
 
Sheriff
Posts: 17031
298
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can see where you might add a test for logging when you have a user story like: "As a system admin or someone doing production support, I would like to be able to find log statements that will help me zero in on a problem quickly so I can resolve it in a timely manner." For ad-hoc logging statements added for the purpose of debugging, I wouldn't write any tests though.

And it's true, Jeff, what you said about over-logging and under-logging. I find that we often over-log about things like "Entered/exiting foo method" and under-log about things that could help us find problems quicker. That could be just 20-20 hindsight though. Sometimes you don't realize you should have logged something until you're in a situation where you wish you had.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic