isEnabled

public final boolean isEnabled()

Returns true if logging is enabled at the level implied for this API, according to the current logger backend. For example:


  if (logger.atFine().isEnabled()) {
    // Do non-trivial argument processing
    logger.atFine().log("Message: %s", value);
  }

Note that if logging is enabled for a log level, it does not always follow that the log statement will definitely be written to the backend (due to the effects of other methods in the fluent chain), but if this method returns false then it can safely be assumed that no logging will occur.

This method is unaffected by additional methods in the fluent chain and should only ever be invoked immediately after the level selector method. In other words, the expression:

logger.atFine().every(100).isEnabled()
is incorrect because it will always behave identically to:
logger.atFine().isEnabled()

Implementation Note

By avoiding passing a separate Level at runtime to determine "loggability", this API makes it easier to coerce bytecode optimizers into doing "dead code" removal on sections guarded by this method.

If a proxy logger class is supplied for which:

logger.atFine()
unconditionally returns the "NoOp" implementation of the API (in which isEnabled() always returns false), it becomes simple for bytecode analysis to determine that:
logger.atFine().isEnabled()
always evaluates to false .