Hacker News new | ask | show | jobs
by xaphod 4792 days ago
One important aspect of logging is to include enough information when something fails. This sounds like it should be common sense, but I have seen this too many times:

java.net.ConnectionException: Connection refused ...

Why not include at least the hostname and port? And what connection is this exactly that failed? You might be able to find out what it was trying to connect to based on the stack trace, but that requires knowledge of the internal structure of the software.

This seems to be a common problem in software written in Java, I don't know why exactly. Maybe something to do with the way exceptions are handled, so that the relevant information is not available when printing the error?

1 comments

So true! One of my pet peeves! Truly pathetic to not include dynamic info like hostname, port and reason.

Who are these people writing code like that - they never had to debug a problem before? Include as much as you can! A stack trace is only part of the story.

Definitely, I often catch exceptions and wrap them just to add more information from the try-finally scope. It is so frequently useful to get a full story of what the app was attempting to do.