« Volver a Configuring

Configuring Logs

Introduction #

Liferay uses the Apache Log4j library to perform all of it's logging operations. This allows for a very configurable setup with different levels of messages priority, from FATAL to DEBUG. It also allows to configure a different level of messages to be shown for every package or class within Liferay or any of its libraries.

The default configuration is set to only show errors for most classes and packages with a few of them set to show also warnings.

Where are the logs? #

By default, the logs are written to the standard output (CONSOLE in log4j's terminology) which means that they'll be outputted to the application server log file. Here are the location of the logs in some of the application servers supported by Liferay:

  • Tomcat: $TOMCAT/bin/catalina.out
  • Geronimo: $GERONIMO/var/log/geronimo.log
  • JBoss: $JBOSS/server/default/log/
  • Glassfish: $GLASSFISH/domains/domain1/logs/server.log

Customizing the Log4j configuration #

Using the Enterprise Admin Portlet #

The Admin Portlet available to portal administrators offers a UI to dinamically change the log levels for many of the packages of Liferay and its main libraries. To access this UI add the Admin Portlet to a portal page, go to the Server tab and click 'more' so that the subtabs are shown. Go to the 'Log levels' subtab and you should see a screen similar to the following:

By using the dropdown you can select a different log level for each of the paragraphs, from DEBUG to FATAL, or turn them off completely. Once you are finished click the save button to apply your changes. You can do this operation as many times as desired.

This changes are stored in memory, which means that they'll be lost when you reboot the server. If you wish to make changes to the configuration in a way that they are preserved after reboots or that can be maintained accross different installations read the following sections.

Creating a custom configuration file: portal-log4j-ext.xml #

The logging configuration of Liferay is stored in a file called portal-log4j.xml. It's possible to override all or certain parts of that configuration by creating another file called portal-log4j-ext.xml and deploying it to the appropriate place. This section details the steps necessary to achieve this.

The first step is to get a copy of the original configuration file. Depending on our environment the portal-log4j.xml can be found in:

  • Liferay's sources: portal-impl/classes/META-INF/
  • Tomcat bundle: inside $TOMCAT/WEB-INF/lib/portal-impl.jar in META-INF/
  • Other bundles: look for portal-impl.jar, the file will be inside its META-INF directory once unzipped

Note for JBoss users: JBoss includes its own Log4j configuration that may override Liferay's configuration. The JBoss Log4j configuration file can be found in $JBOSS/server/default/conf/log4j.xml. Read the JBoss documentation for details.

Make a copy of that file and rename it as portal-log4j-ext.xml. It is recommended that you only keep in that file those entries that have been modified, delete the other entries, since they'll be loaded from portal-log4j.xml.

Let's see an example of how we could change the log level of a library, for example, Hibernate. By default the log level of this library is ERROR. Let's change it to INFO. Look in the file for the following entry:

  <category name="org.hibernate">
    <priority value="ERROR" />

A portal-log4j-ext.xml file that changes only this log level would be:

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

Once you've done the necessary changes deploy the file. The file has to be deployed inside a directory called META-INF to a directory that is in the classpath. Here are some recommended locations, depending on the application server:

  • Tomcat 5.x: $TOMCAT/common/classes/META-INF
    • Note: To this directory, you also need to copy log4j.dtd from the same location where you obtained the portal-log4j.xml file. Else, you will encounter errors about the fact that log4j.dtd cannot be resolved.
  • Tomcat 6.x: $TOMCAT_HOME/lib/META-INF
    • Note: As in Tomcat 5.x, you also need to copy log4j.dtd.
  • Geronimo: One possibility to do is is by adding a .jar file containing the META-INF/log4j.dtd (as with Tomcat) and the META-INF/portal-log4j-ext.xml to Geronimo's $GERONIMO_HOME/lib directory. In a hurry, just adding the directory and files to one of the existing .jar files (i.e. log4j-1.x.jar) in the directory is also possible; this way, you do not have to create your own jar for it.
  • Tomcat 7.2.3: $TOMCAT_HOME/webapps/ROOT/WEB-INF/classes/META-INF
    • Note: Copy log4j.dtd as well as portal-log4j-ext.xml, replacing webapps/ROOT with the Liferay-Installation directory.
  • Glassfish 3.1.2: domain-dir/lib/classes/META-INF/portal-log4j-ext.xml
  • Other application servers: TBD

Note: If you are using an extension environment, it can only store and deploy for you a portal-log4j-ext.xml file. See Development in the ext environment for detailed instructions. When using the ext environment the portal-log4j-ext.xml file will be automatically included in your installation when using the deploy ant targets.

Appending logs to a file #

Customize the log4j.properties file to append the logs to a file: log4j.appender.CONSOLE=org.apache.log4j.FileAppender

And also specify where the file will be located: log4j.appender.CONSOLE.File=E:/Liferay/5.1/liferay-portal-tomcat-5.5-5.1.0/logs/test.log

Technical information #

Log4 initialization #

The initialization of Log4j is performed in the InitAction.run() method which is executed when the application server starts up. This method is invoked when the MainServlet class is loaded because of the following code that can be find within it:

 static {

The InitUtil class is just a helper class that ends up invoking InitAction.run().

The InitAction class loads two log4j configuration files, portal-log4j.xml and portal-log4j-ext.xml with the second one overriding the configuration of the first. If any of this files is missing they are silently ignored. This is the code that performs this operation:

  if (GetterUtil.getBoolean(SystemProperties.get("log4j.configure.on.startup"), true) && !ServerDetector.isSun()) {
    ClassLoader classLoader = getClass().getClassLoader();

Note: This code may have slightly changed since this article was written or may be different for your version. Make sure you download Liferay's sources and look at your specific version of the mentioned files for accurate information.

Troubleshooting #

If you have setup a portal-log4j-ext.xml file but your changes are not being applied there are two possible causes:

  • The file has an incorrect syntax
  • The file is not being found

If you can't see any information in the logs to help you determine the cause, the best way to find out is to do some debugging:

  1. Configure your IDE to be able to connect to a remote Liferay instance for debugging or to be able to run Liferay within it
  2. Set up a breakpoint in the line where the ClassLoader is defined (see code fragment above)
  3. Run Liferay with remote debugging enabled or within the IDE
  4. If using remote debugging connect to Liferay very quickly after starting it (within the first 2 secs). The Log4J configuration happens very early in the startup. If the debugger does not stop in the breakpoint, stop Liferay and try again.
  5. Execute step-by-step and enter the configureLog4J method for the portal-log4j-ext.xml file to find out if the file is found and if it's read correctly
0 archivos adjuntos
233191 Accesos
Promedio (3 Votos)
La valoración media es de 4.33333333333333 estrellas de 5.
Respuestas anidadas Autor Fecha
Related to this, I have created an article... Juan Fernández 15 de diciembre de 2009 2:03
"Appending logs" to a file doesn't work with 5.2? Chris Whittle 9 de agosto de 2010 13:52
are you able to make it work? Nagendra Kumar Busam 14 de septiembre de 2010 9:00
Neither with 6.0.5. Henrique Fernandes 17 de diciembre de 2010 4:26
Sorry, file and console appenders are working... Henrique Fernandes 20 de diciembre de 2010 1:27
for Tomcat 6.x, why we should put put the... Jay XU 7 de septiembre de 2010 2:26
No, that's not working for me. In Liferay 6,... Dan Smith 21 de septiembre de 2010 9:16
That's fine with:... Dan Smith 28 de septiembre de 2010 8:23
I could not make it work Liferay v6.0 with... Alberto Gallardo 6 de octubre de 2010 10:02
What works for me with Liferay 6.0.4 on a... Andrea Caltroni 4 de noviembre de 2010 6:04
Hi, I have set in the Admin portlet the log... vikash kumar chaurasia 6 de diciembre de 2010 22:36
See... Henrique Fernandes 15 de diciembre de 2010 8:06
Log4j Working with Liferay 6.0.5, for multiple... Prakash Khanchandani 23 de febrero de 2011 7:41
The above technique by Prakash worked for me.... Rick Umali 5 de mayo de 2011 12:23
Excellent article thank you! Nicolas Forney 20 de julio de 2011 9:12
Hi, nice guide. Unfortunately in Glassfish it... Riccardo Rotondo 12 de octubre de 2011 6:47
Nice article. Thanks. What worked for me was... Wole Adetiba 7 de diciembre de 2011 0:28
For users of Liferay 6.x, the following link to... Ben Carson 13 de junio de 2012 13:05
@Prakash Khanchandani I want to debug Liferay... Sunil Rai 18 de julio de 2012 5:20
I have do below configurations: 1. Get... python shi 27 de febrero de 2013 0:15
Awesome!!!, I was facing the issue... Nelson Aguayo 11 de febrero de 2014 8:45

Related to this, I have created an article called "How to create custom loggin" to explain how to do this for your own portlets.

Here's the link: http://www.liferay.com/web/guest/community/wiki/-/wiki/Main/How+to+create+custom­+logging
Publicado el día 15/12/09 2:03.
"Appending logs" to a file doesn't work with 5.2?
Publicado el día 9/08/10 13:52.
for Tomcat 6.x, why we should put put the config file under $TOMCAT_HOME/lib, we should not put any config file here

why don't you put it under webapps/ROOT/WEB-INF/classes/META-INF
Publicado el día 7/09/10 2:26.
are you able to make it work?
Publicado el día 14/09/10 9:00 en respuesta a Chris Whittle.
No, that's not working for me.

In Liferay 6, the InitUtil.class refers to META-INF\portal-log4j-ext.xml,
so I put the modified portal-log4j-ext.xml into

I tried first:

without more success. Do you have an idea?

Publicado el día 21/09/10 9:16.
That's fine with:
Publicado el día 28/09/10 8:23 en respuesta a Dan Smith.
I could not make it work Liferay v6.0 with glassfish. I'm only using portlets plugin. Did anyone get it?

I have found quite frustrated that liferay creates a log4j.jar and a log4j.properties for every portlet that it deploys. This combination does not work properly in glassfish v.2.1.1, as these files already exists for the liferay module: Depending on what ClassLoader loads the log4j, a <<"ConsoleAppender" object is not assignable to a "org.apache.log4j.Appender" variable>> is thrown.
Publicado el día 6/10/10 10:02.
What works for me with Liferay 6.0.4 on a custom portlet using Spring and Hibernate is just using a log4j.properties configuration file and putting it in WEB-INF/classes of the portlet.

I removed the portal-log4j-ext.xml and log4j.dtd from <LIFERAY_TOMCAT_HOME>/webapps/ROOT/WEB-INF/classes/META-INF/
(which was not working) and I have no configuration in Control Panel --> Server Administration --> Log Levels for my classes.

In the classes I instantiate the logger with:

static Logger logger = Logger.getLogger(YourClass.class);
Publicado el día 4/11/10 6:04 en respuesta a Alberto Gallardo.

I have set in the Admin portlet the log level as DEBUG for one of the package used in my portlet. However, I am not getting the debug level messages in the log generated?

I am able to get the INFO and ERROR and other (except DEBUG) level logs.

Can anybody suggest me.

For detailed description plz go to the URL:
Publicado el día 6/12/10 22:36 en respuesta a Andrea Caltroni.
See http://www.liferay.com/community/forums/-/message_boards/message/6814315/maximiz­ed?_19_preview=false#_19_message_6814315
Publicado el día 15/12/10 8:06 en respuesta a Alberto Gallardo.
Publicado el día 17/12/10 4:26 en respuesta a Chris Whittle.
Sorry, file and console appenders are working with the portal-log4j-ext.xml extension under $TOMCAT_HOME\webapps\ROOT\WEB-INF\classes\META-INF\.
Publicado el día 20/12/10 1:27 en respuesta a Henrique Fernandes.
Log4j Working with Liferay 6.0.5, for multiple appenders
The following worked for me:
1) I placed the two files portal-log4j-ext.xml and log4j.dtd inside the $TOMCAT/lib/META-INF
2) the code inside the portal-log4j-ext.xml

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

<appender name="MY_APPENDER" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${catalina.home}/logs/myAppender.log"/>
<param name="MaxFileSize" value="10000KB"/>
<param name="MaxBackupIndex" value="10"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="----- %n%d{yyyy/MM/dd HH:mm:ss} %p%n%l [%x][%t] %n%m%n" />

<logger name="com.my.base.package">
<level value="INFO" />
<appender-ref ref="MY_APPENDER" />


I have not used the <root> tag, as it will still be used to print to the Console and the above will print to the log file inside $TOMCAT/logs/.

we can also use <root> instead of <logger>:
<appender-ref ref="CONSOLE" /> <!-- This being the default appender inside portal-log4j.xml -->
<appender-ref ref="MY_APPENDER" />

My environment: Liferay 6.0.5 and tomcat-6.0.26.
Don't know if this is the best way. Hope this helps.
Thanks Chris Whittle for giving the hint in your other post
Publicado el día 23/02/11 7:41.
The above technique by Prakash worked for me. Thanks for posting this!
Publicado el día 5/05/11 12:23 en respuesta a Prakash Khanchandani.
Excellent article thank you!
Publicado el día 20/07/11 9:12 en respuesta a Rick Umali.
Hi, nice guide.
Unfortunately in Glassfish it works in a different way. I'm deploying a portlet by netbeans but I'm not able to set the logger level at debug. Any suggestions ? Thanks in advance.
Publicado el día 12/10/11 6:47 en respuesta a Nicolas Forney.
Nice article. Thanks. What worked for me was having the portal-log4j-ext.xml extension under $TOMCAT_HOME\webapps\ROOT\WEB-INF\classes\META-INF\.
Publicado el día 7/12/11 0:28 en respuesta a Riccardo Rotondo.
For users of Liferay 6.x, the following link to the Liferay User's Guide should get you up and running.
So much easier than the steps listed in this wiki. Just create a Log object in your code and a 'category' in the server console.
Publicado el día 13/06/12 13:05 en respuesta a Wole Adetiba.
@Prakash Khanchandani I want to debug Liferay 6.0.6 CE LDAP for the following:


But its not working at my end. Can you please guide me for the same.

Publicado el día 18/07/12 5:20 en respuesta a Ben Carson.
I have do below configurations:
1. Get portal-log4j.xml from Liferay's sources: portal-impl/classes/META-INF/, rename it as portal-log4j-ext.xml. Change it to
<?xml version="1.0"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="DMSServiceLog" class="com.icil.fw.logging.ICILRollingFileAppender">
<param name="File" value="${catalina.home}/logs/dms_log/dms.log"/>
<param name="MaxFileSize" value="10000KB"/>
<param name="MaxBackupIndex" value="10"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}(%F:%L)] [%X{username}] - %m%n" />
<logger name="com.icil.dms.portlet">
<level value="INFO" />
<appender-ref ref="DMSServiceLog" />

2. Put file portal-log4j-ext.xml, log4j.dtd to TOMCAT_HOME/webapps/ROOT/WEB-INF/classes/META-INF.

3. restar tomcat6, but throw exception:
log4j:ERROR Could not create an Appender. Reported error follows.
java.lang.ClassCastException: com.icil.fw.logging.ICILRollingFileAppender cannot be cast to org.apache.log4j.Appender
at org.apache.log4j.xml.DOMConfigurator.parseAppender(DOMConfigurator.java:248)
at org.apache.log4j.xml.DOMConfigurator.findAppenderByName(DOMConfigurator.java:176­)
at org.apache.log4j.xml.DOMConfigurator.findAppenderByReference(DOMConfigurator.jav­a:191)
at org.apache.log4j.xml.DOMConfigurator.parseChildrenOfLoggerElement(DOMConfigurato­r.java:523)
at org.apache.log4j.xml.DOMConfigurator.parseCategory(DOMConfigurator.java:436)
at org.apache.log4j.xml.DOMConfigurator.parse(DOMConfigurator.java:999)
at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:867)
at org.apache.log4j.xml.DOMConfigurator.doConfigure(DOMConfigurator.java:815)
at com.liferay.util.log4j.Log4JUtil.configureLog4J(Log4JUtil.java:79)
at com.liferay.util.log4j.Log4JUtil.configureLog4J(Log4JUtil.java:58)
at com.liferay.portal.util.InitUtil.init(InitUtil.java:94)
at com.liferay.portal.spring.context.PortalContextLoaderListener.contextInitialized­(PortalContextLoaderListener.java:134)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4205­)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4704)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
­at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)
a­t org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1315)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.ja­va:142)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1061)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at­ sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav­a:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)

My class com.icil.fw.logging.ICILRollingFileAppender is extends RollingFileAppender, but stilll throw excetpion: java.lang.ClassCastException: com.icil.fw.logging.ICILRollingFileAppender cannot be cast to org.apache.log4j.Appender
What is the reason?
Publicado el día 27/02/13 0:15 en respuesta a Prakash Khanchandani.
Awesome!!!, I was facing the issue https://issues.liferay.com/browse/LPS-36627
with liferay 6.2, now I apply the file portal-log4j-ext.xml inside the portal-impl.jar (portal-impl/META-INF/)

<?xml version="1.0"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<category name="portal-web.docroot.errors.404_jsp">
<priority value="DEBUG" />

Thanks you!
Publicado el día 11/02/14 8:45.