Liferay: Líder no Quadrante Mágico da Gartner pelo sexto ano consecutivo! Leia mais aqui
« Voltar para 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="">
  <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 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 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

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 Anexos
179006 Visualizações
Média (3 Votos)
A média da avaliação é 4.33333333333333 estrelas de 5.
Respostas do tópico Autor Data
Related to this, I have created an article... Juan Fernández 15 de Dezembro de 2009 02: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 Setembro de 2010 09:00
Neither with 6.0.5. Henrique Fernandes 17 de Dezembro de 2010 04:26
Sorry, file and console appenders are working... Henrique Fernandes 20 de Dezembro de 2010 01:27
for Tomcat 6.x, why we should put put the... Jay XU 7 de Setembro de 2010 02:26
No, that's not working for me. In Liferay 6,... Dan Smith 21 de Setembro de 2010 09:16
That's fine with:... Dan Smith 28 de Setembro de 2010 08:23
I could not make it work Liferay v6.0 with... Alberto Gallardo 6 de Outubro de 2010 10:02
What works for me with Liferay 6.0.4 on a... Andrea Caltroni 4 de Novembro de 2010 06:04
Hi, I have set in the Admin portlet the log... vikash kumar chaurasia 6 de Dezembro de 2010 22:36
See... Henrique Fernandes 15 de Dezembro de 2010 08:06
Log4j Working with Liferay 6.0.5, for multiple... Prakash Khanchandani 23 de Fevereiro de 2011 07:41
The above technique by Prakash worked for me.... Rick Umali 5 de Maio de 2011 12:23
Excellent article thank you! Nicolas Forney 20 de Julho de 2011 09:12
Hi, nice guide. Unfortunately in Glassfish it... Riccardo Rotondo 12 de Outubro de 2011 06:47
Nice article. Thanks. What worked for me was... Wole Adetiba 7 de Dezembro de 2011 00:28
For users of Liferay 6.x, the following link to... Ben Carson 13 de Junho de 2012 13:05
@Prakash Khanchandani I want to debug Liferay... Sunil Rai 18 de Julho de 2012 05:20
I have do below configurations: 1. Get... python shi 27 de Fevereiro de 2013 00:15
Awesome!!!, I was facing the issue... Nelson Aguayo 11 de Fevereiro de 2014 08: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:­+logging
Postado em 15/12/09 02:03.
"Appending logs" to a file doesn't work with 5.2?
Postado em 09/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
Postado em 07/09/10 02:26.
are you able to make it work?
Postado em 14/09/10 09:00 em resposta 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?

Postado em 21/09/10 09:16.
That's fine with:
Postado em 28/09/10 08:23 em resposta 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 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.
Postado em 06/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 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);
Postado em 04/11/10 06:04 em resposta 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:
Postado em 06/12/10 22:36 em resposta a Andrea Caltroni.
Postado em 15/12/10 08:06 em resposta a Alberto Gallardo.
Neither with 6.0.5.
Postado em 17/12/10 04:26 em resposta 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\.
Postado em 20/12/10 01:27 em resposta 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="">

<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="">
<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
Postado em 23/02/11 07:41.
The above technique by Prakash worked for me. Thanks for posting this!
Postado em 05/05/11 12:23 em resposta a Prakash Khanchandani.
Excellent article thank you!
Postado em 20/07/11 09:12 em resposta 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.
Postado em 12/10/11 06:47 em resposta 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\.
Postado em 07/12/11 00:28 em resposta a Riccardo Rotondo.
For users of Liferay 6.x, the following link to the Liferay User's Guide should get you up and running.­liferay-s-logging-syst-5
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.
Postado em 13/06/12 13:05 em resposta 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.

Postado em 18/07/12 05:20 em resposta 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="">
<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(
at org.apache.log4j.xml.DOMConfigurator.findAppenderByName(­)
at org.apache.log4j.xml.DOMConfigurator.findAppenderByReference(DOMConfigurator.jav­a:191)
at org.apache.log4j.xml.DOMConfigurator.parseChildrenOfLoggerElement(DOMConfigurato­
at org.apache.log4j.xml.DOMConfigurator.parseCategory(
at org.apache.log4j.xml.DOMConfigurator.parse(
at org.apache.log4j.xml.DOMConfigurator.doConfigure(
at org.apache.log4j.xml.DOMConfigurator.doConfigure(
at com.liferay.util.log4j.Log4JUtil.configureLog4J(
at com.liferay.util.log4j.Log4JUtil.configureLog4J(
at com.liferay.portal.util.InitUtil.init(
at com.liferay.portal.spring.context.PortalContextLoaderListener.contextInitialized­(
at org.apache.catalina.core.StandardContext.listenerStart(­)
at org.apache.catalina.core.StandardContext.start(
at org.apache.catalina.core.ContainerBase.addChildInternal(
­at org.apache.catalina.core.ContainerBase.addChild(
at org.apache.catalina.core.StandardHost.addChild(
at org.apache.catalina.startup.HostConfig.deployDirectory(
at org.apache.catalina.startup.HostConfig.deployDirectories(
a­t org.apache.catalina.startup.HostConfig.deployApps(
at org.apache.catalina.startup.HostConfig.start(
at org.apache.catalina.startup.HostConfig.lifecycleEvent(
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.ja­va:142)
at org.apache.catalina.core.ContainerBase.start(
at org.apache.catalina.core.StandardHost.start(
at org.apache.catalina.core.ContainerBase.start(
at org.apache.catalina.core.StandardEngine.start(
at org.apache.catalina.core.StandardService.start(
at org.apache.catalina.core.StandardServer.start(
at org.apache.catalina.startup.Catalina.start(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at­ sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav­a:43)
at java.lang.reflect.Method.invoke(
at org.apache.catalina.startup.Bootstrap.start(
at org.apache.catalina.startup.Bootstrap.main(

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?
Postado em 27/02/13 00:15 em resposta a Prakash Khanchandani.
Awesome!!!, I was facing the issue
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="">
<category name="portal-web.docroot.errors.404_jsp">
<priority value="DEBUG" />

Thanks you!
Postado em 11/02/14 08:45.