Liferay Log Levels Configuration

  

Liferay Log Levels Configuration


Overview


This article explains how to use log4j logger in Liferay and configure the log levels for both Liferay and custom modules.


Using Logger


Logging in Liferay can be used in the following way:


import com.liferay.portal.kernel.log.Log;

import com.liferay.portal.kernel.log.LogFactoryUtil;


public class LoggerConfiguration {


   public static void loggerTest() {

       _log.info("LoggerConfiguration => INFO.");

   }


   private static final Log _log = LogFactoryUtil.getLog(LoggerConfiguration.class);

}


The logger object can be created with the com.liferay.portal.kernel.log.LogFactoryUtil class.

Then it can be used to log messages of different levels (TRACE|DEBUG|INFO|WARN|ERROR|FATAL).


Default Log Level


Default log level is INFO:



Log Levels Configuration


Log level can be configured in Control Panel -> Server Administration -> Log Levels:


For each category (package and class) the appropriate log level can be defined.

By default, only Liferay classes/packages are included.

See next section to check how to add custom classes to log levels configuration.


Note: this configuration is not persisted, and will be reverted after server restart.

 

  

Log Levels for Custom Code


To make custom classes configurable inside Log Levels configuration a module-log4j.xml file should be created in {module}/src/main/resources/META-INF folder with the following content:


<?xml version="1.0"?>

<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

  <category name="com.lifedev.logger.LoggerConfiguration">

     <priority value="DEBUG" />

  </category>

</log4j:configuration>



, where category - class or package name, priority - log level.

Once module with configuration is deployed - appropriate classes/packages should be available in configuration:


After changing the log level changes should be applied automatically:

But to make such changes persistent - module should be re-deployed with appropriate changes in module-log4j.xml.



Enjoy 😏

Comments

Popular posts from this blog

Liferay Search Container Example

Liferay DXP - max upload file size

Liferay Keycloak integration