Creating custom logger files for your portlet and also default logger file for server .
Disabling console appender .
Step 1:Create a ext portlet using liferay IDE .
Step 2: create a META-INF folder under ext-impl/src (src) and create a portal-log4j-ext .xml add log4j.dtd file
Example: portal-log4j-ext .xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- additional custom logging -->
<appender name="file" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${catalina.base}/logs/srikanthcustom.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %5p %c{1}:%L - %m%n"/>
</layout>
</appender>
<!-- general application log -->
<appender name="liferayFile" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="${catalina.base}/logs/liferay.log"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %5p %c{1}:%L - %m%n"/>
</layout>
</appender>
<!—Custom portlet logging -->
<category name="com.test.sample">
<priority value="INFO" />
<appender-ref ref="file"/>
</category>
<!-- default logging -->
<root>
<priority value="INFO" />
<appender-ref ref="liferayFile"/>
</root>
</log4j:configuration>
Explaination: The above code will create a 2 log file under server(tomcat)\logs
1:liferay.log as default log file,It appends all the default logs .
2: srikanthcustom.log (newsroom in example below)file,this file appends only logs from the package which are metioned in the category,as shown below.
<category name="com.test.sample">
<priority value="INFO" />
<appender-ref ref="file"/>
</category>
Note: Once you create the ext portlet ,after deploying wait for few seconds and then restart the server to see the effects.
Thank you very much!
ReplyDeleteThis old guide saved me from hours of headache..
It's valid even on Liferay 6.2 and Tomca7
Thank you. Very useful. Here there's a sample project i have prepared: https://bitbucket.org/etebes/logarchivoseparado
ReplyDeleteIt works on Liferay 6.1.2 over Tomcat