Liferay Logging

Tags: development

Definition of levels #

Log levels

TRACE The TRACE Level designates finer-grained informational events than the DEBUG. On entry and exit of methods of interest, should log variable values if possible as well.
DEBUG The DEBUG Level designates fine-grained informational events that are most useful to debug an application. For pertinent debugging information (e.g. exporting XYZ document, completed exporting XYZ document), may include performance logging information.
INFO The INFO level designates informational messages that highlight the progress of the application at coarse-grained level. (e.g. "starting exports for DL Portlet", "completing exports for DL Portlet")
WARN The WARN level designates potentially harmful situations. (e.g. Unexpected data in the process)
ERROR The ERROR level designates error events that might still allow the application to continue running (e.g. unexpected Exception is thrown while generating a page)
FATAL  The FATAL level designates very severe error events that will presumably lead the application to abort. (e.g. There’s no database connection)

Following the rules from log4j API

Code examples #

Creating the log message is an expensive operation so we should avoid doing it unless we know it’s necessary. For most of the classes, the debug and the trace level will be switched off by default and to save time, we should only build the message when they are enabled:

TRACE level:

if (_log.isTraceEnabled()) {
    _log.trace("Returning read data source");
}

ERROR level:

_log.error("Portal class loader is not available to override the " +
    "default Catalina web class loader");

In the portal you should always check if the log level is enabled if you are logging with a level which is below ERROR.

Examples #

What level should I use if #

  • I want to indicate that the LAR export had started: INFO
  • There’s invalid data in the process: WARN
  • I want to add some code which measures how much time each sub task takes (stopwatch): DEBUG
  • I want to indicate what items are exported: DEBUGI want to log the SQL query the portal will run: DEBUG
  • the portal catches an Exception and doing nothing: DEBUG 
0 Attachments
4337 Views
Average (0 Votes)
The average rating is 0.0 stars out of 5.
Comments
No comments yet. Be the first.