Following the Great Relogging activity that took place recently, a revised format for logging in Java code is established as follows:
Logging.LOGGING
compile-time flag has been removed. Do not use it.
log
.
org.apache.log4j.Category
is deprecated in favor of org.apache.log4j.Logger
. Example:private static final Category log = Logging.LOGGING ? Category.getInstance(POD.class) : null;
private static final Logger log = Logger.getLogger(POD.class);
log.isFatalEnabled() // currently unused
log.isErrorEnabled()
log.isWarnEnabled()
log.isInfoEnabled()
log.isDebugEnabled()
log.isTraceEnabled() // currently unused
if (log.isInfoEnabled())
{
log.info("restoreRecordings: Storage not ready - deferring load of recording database");
}
log.info(...);
call. The following should not be used:if (log.isInfoEnabled())
log.info("restoreRecordings: Storage not ready - deferring load of recording database");
if (log.isInfoEnabled()) log.info("restoreRecordings: Storage not ready - deferring load of recording database");
if (log.isXXXEnabled())
check, even where there are two consecutive log messages in the source. Example:if (log.isDebugEnabled()
{
log.debug("Destroy called. Ok.");
}
if (log.isDebugEnabled()
{
log.debug("Received Tuning Over failed event");
}
if (log.isDebugEnabled()
{
log.debug("Destroy called. Ok.");
log.debug("Received Tuning Over failed event");
}
if (low)
{
if (log.isWarnEnabled())
{
log.warn("VM memory low even after reclamation");
}}
if (log.isWarnEnabled() && low)
{
log.warn("VM memory low even after reclamation");
}
if (log.isWarnEnabled())
{
if (low)
{
log.warn("VM memory low even after reclamation");
}}
For reference, here is the link to our coding guidelines. Refer to section 2.4: Logging Guidelines.