Recently I was at a client site, who had just over 30 portlets deployed. When debugging was enabled, catalina.out was so saturated with log statements that it was nearly impossible to track what needed to be tracked. I changed their portlets to log to both the console like normal, and also to log to it's own file. After looking around a bit, I see this is a somewhat common quesiton in the Liferay forums, so I've decided to paste my solution here for all to use. I always use the Liferay plugins sdk, so this example will reflect those paths. If you do something different, just keep that in mind.
Goal:
To have a portlet log to both catalina.out (the console) and to it's own file, in bundles/logs/porlet-name-(date).log
Solution:
Create: /path/to/plugins/sdk/portlets/myloggingexample-portlet/docroot/WEB-INF/src/
inside the src folder, I added two files: log4j.xml and log4j.dtd
I grabbed the log4j.dtd from the liferay portal source
Content of log4j.xml
<?xml version="1.0"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}:%L] %m%n" />
</layout>
</appender>
<appender name="FILE" class="org.apache.log4j.rolling.RollingFileAppender">
<rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="FileNamePattern" value="../../logs/
portlet-name.%d{yyyy-MM-dd}.log" />
</rollingPolicy>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}:%L] %m%n" />
</layout>
</appender>
<category name="com.myclient" >
<priority value="TRACE" />
</category>
<root>
<priority value="INFO" />
<appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" />
</root>
</log4j:configuration>
--------
We have now configured log4j, but we don't have the jars yet! To get those modify
liferay-plugin-package.properties and add:
portal-dependency-jars=\
log4j.jar,\
log4j-extras.jar
Now, when the portlet is deployed those jars will automatically be taken from Liferay to ensure version consistency.
Lastly, you need to setup your logger in your class. Add:
import org.apache.log4j.Logger;
to your imports, and inside your class (I do is as the last line), add:
private static Logger _log = Logger.getLogger(MyClassName.class);
and with that, you can call _log.fatal("test"); and see that it shows up both in the console and one directory above tomcat, in the logs folder. I set it up that way because we have bundles/logs and bundles/tomcat, so my file will show up in bundles/logs/myportlet-name-date.log
Hopefully this will make debugging and log viewing a little less messy for you!