When to log? (best practices and localization)



Hello!

I am wondering for some time now:

When do you actually make use of some logging tool generally? I need
some motivation and benefits. Sure logging is a must for most/all
server apps as well as well as apps that have no console to print to.
Sooner or later any software will be deployed and mostly all apps
won't have a console available. So the short answer would probably be
to use a logging tool whenever you can over any System.out or
System.err prints, but this seems to include (too) much overhead. Is
it?

I'm rather vague on what I really want to ask here, I simply don't
know when to use a logging tool and when System prints are "enough".

I often write code like below (the code simply gets all IP addresses
given some host name):

public myMethod(...)
{

....

InetAddress[] ias = null;

try
{
ias = InetAddress.getAllByName(strHostName);
}
catch ( UnknownHostException e )
{
Log log = LogFactory.getLog(getClass());
log.error("Failed to get IP addresses from " + strHostName + "!",
e);
//return false??? or null
}
catch ( SecurityException e )
{
Log log = LogFactory.getLog(getClass());
log.error("Failed to get IP addresses from " + strHostName + "!",
e);
//return false??? or null
}

....

return true;
}

Is it better to log here or should the caller of the method log
depending on what is returned? This would of course hide the exception
which was thrown. What is the best practice if one can say at all?

Is it common to use localized messages for the logs (the app IS
localized)?

What is the best way to implement a log window? Find the log file and
display it in a text component? Again, would the best practice be to
localize those messages? I tend to rather not doing it, as opposed to
messages displayed on the GUI...

I would be thankful for any practical advice on this, what the best
practices are as seen from your subjective perspective.

TIA
Karsten

PS: What is the more predominant term, internationalization (I18n) or
localization (L10n)?

.