The log object

You can log arbitrary strings as your code executes using the log object. You can use the log object to debug your code and to keep track of exactly what happened during your code's execution.
lac40
You can log arbitrary strings as your code executes using the
log
object. You can use the
log
object to debug your code and to keep track of exactly what happened during your code's execution.
Logging is done at the following levels:
  • error
    : Serious problems that make the system unusable.
  • info
    : Logging messages that reflect high-level activity that may be of interest.
  • debug
    : High-level debugging messages.
    This logging level is typically used during development, but not in production.
  • finer
    : Medium-level debugging messages.
    This logging level is typically used during development, but not in production.
  • finest
    : Low-level debugging messages.
    This logging level is typically used during development, but not in production.
  • warn
    : Problems that can negatively impact the performance of the system, but are not fatal.
Logging goes to the 
log
object, which always has a logging level. That logging level determines whether the logging call results in logging. If the logging level for the log object is higher than the logging call's logging level, then the logging call does nothing. You can turn logging up and down depending on how much details you require.
In the following example, logging is done at a level (
info
) that is lower than the current logging level (
warn
). Since the logging level is
warn
, then the following code does not result in logging:
log.info("My informational message");
You can control the logging level in multiple ways, at the auth token level, or with URL parameters.
Optimization
It is generally a good idea to log no more than required, because logging is not free: it can affect performance. In particular, logging can be expensive if it requires executing code that takes up a lot of resources.
If you are logging a fixed message, then it is perfectly fine to not worry about this. For example, use the
log.debug ()
method:
log.debug("My message goes here"); 
However, if your logging message invokes other functions, or builds up a string from other objects, you should make it conditional on the logging level. For example, use the
log.isDebugEnabled ()
method:
if (log.isDebugEnabled()) {
    log.debug("The value of foo is:" + foo.getValue() + " and the value of bar is:" + bar);
}
If you do not make the logging conditional on the logging level and you turn down the logging level, you still incur the cost of building this string, even though it is never actually logged. This is typically not a big deal, but it can add up.