Adjusting Module Logging

Liferay DXP uses Log4j logging services. Here are the ways to configure logging for module classes and class hierarchies.

  • Log Levels in Liferay DXP’s UI
  • Configure Log4j for multiple modules in a [anyModule]/src/main/resources/META-INF/module-log4j.xml file.
  • Configure Log4j for a specific module in a [Liferay Home]/osgi/log4j/[symbolicNameOfBundle]-log4j-ext.xml file.
  • Configure Log4j for an OSGi fragment host module in a /META-INF/module-log4j-ext.xml file

Here’s an example Log4j XML configuration:

<?xml version="1.0"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
    <category name="org.foo">
        <priority value="DEBUG" />
    </category>
</log4j:configuration>

Use category elements to specify each class or class hierarchy to log messages for. Set the name attribute to that class name or root package. The example category sets logging for the class hierarchy starting at package org.foo. Log messages at or above the DEBUG log level are printed for classes in org.foo and classes in packages starting with org.foo.

Set each category’s priority element to the log level (priority) you want.

  • ALL
  • DEBUG
  • INFO
  • WARN
  • ERROR
  • FATAL
  • OFF

The log messages are printed to Liferay log files in [Liferay_Home]/logs.

You can see examples of module logging in several Liferay sample projects. For example, the action-command-portlet, document-action, and service-builder/jdbc samples (among others) leverage module logging.

That’s it for module log configuration. You’re all set to print the information you want.

Implementing Logging

« Connecting to JNDI Data SourcesImplementing Logging »
Was this article helpful?
0 out of 1 found this helpful