Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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: 17652
300
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.
 
A feeble attempt to tell you about our stuff that makes us money
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic