is isLoggable necessary here, and when I shoud use it?
I see lots of code like below, Does logging method itself do some cheap checking before logging the msg? I mean is it nessary to call isLoggable(...) everytime before the actural logging? Thx.
if (logger.isLoggable(Level.WARNING)) {
logger.warning("filename argument is required.");
}
It's only necessary to do that for performance reasons if logging takes up a significant proportion of your processing time. And if logging takes up a significant proportion of your processing time, you are probably doing way too much logging.
And you'll find that logger.warning starts out by calling logger.isLoggable anyway, so you're duplicating that effort. The only way that improves things is (as OnBringer already said) that you can avoid evaluating the parameters of the logger.warning() method. In your particular example you're doing an extra if-statement to avoid evaluating a string constant.
This is most useful for DEBUG level logging. If debug is not enabled you want to reduce its impact to a minimum (as debug logging tends to be very verbose).
Where I work we have a commit trigger that refuses to commit work that has unchecked debug logging (its useful).
In other cases it is useful if that section of code can produce significant qantities of log info (esp. logs that require string concat or expensive toString() calls). INFO levels should also have serious consideration for this as they can also be verbose and are normally disabled.
its generally not needed for WARN or ERROR logs as people tend to want those and they SHOULD be pretty rare.
matfud