Introduction
Sentry [1] is a great tool for error tracking and Liferay [2] is a very popular portal software that we deploy for out customer as part of our main product.Log4j configuration with Liferay
As stated in [3], custom log4j configuration is done adding these files:- portal-log4j-ext.xml
- log4j.dtd
The portal-log4j-ext.xml overrides the file portal-log4j.xml which can be found inside portal-impl.jar (in webapps/ROOT/WEB-INF/lib). You can get a copy from here [4]. The companion file log4j.dtd can be found here [5].
Get Sentry Java Client (raven-java)
To log any errors in our Liferay instance to Sentry, we need a Sentry Java Client which works together with log4j (a Log4j appender) and can be downloaded from here [7].Although Liferay already includes log4j 1.2.x we choose the jar that includes all dependencies (for a reason I explain below):
Download the file raven-log4j-[version]-jar-with-dependencies.jar where [version] is currently: 1.0-SNAPSHOT.
Configure Liferay to log to Sentry
This is done it two steps:- Copy the downloaded raven-log4j JAR to tomcat-/lib
- Customize portal-log4j-ext.xml
Copy raven-log4j file
Copy the downloaded raven-[version]-jar-with-dependencies.jar to tomcat-[version]/lib.Although all the java dependencies should normally live together with the web application and the downloaded file contains log4j 1.2.x, we have chosen this approach for the following reasons:
- Then specific log4j appender and Sentry java client (raven-java) will be available for other deployed web applications. Take into account that in Liferay deployment each extra portlet is considered a separate web application with its own J2EE application context. Each of them will have to be configured individually to log to Sentry.
- The log4j version included in raven-log4j-[version]-jar-with-dependencies.jar has the same major and minor version (1.2), i.e. the Sentry log appender (SentryAppender and AsyncSentryAppender) should be 100% compatible. Special caution should be given when using other versions.
- The tomcat/lib contains class libraries (JAR) which are shared between all of the deployed web applications (WAR). But (!) the J2EE classloader magic avoids calls from a shared class library back to a web application class. In this case, it doesn't happen.
- The web application classes and class libraries have preference when searching for a class
Customize portal-log4j-ext.xml
Following this example [6] where Nuxeo is configured for Sentry, we have to add an appender and activate it in portal-log4j-ext.xml, like this: <?xml version="1.0"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender class="org.apache.log4j.ConsoleAppender" name="CONSOLE">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}:%L] %m%n" />
</layout>
</appender>
<appender class="org.apache.log4j.rolling.RollingFileAppender" name="FILE">
<rollingpolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
<param name="FileNamePattern" value="@liferay.home@/logs/liferay.%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>
<appender class="net.kencochrane.raven.log4j.SentryAppender" name="Sentry">
<param name="dsn" value="http://[two hashes separared by a colon]@log.tangrambpm.es/5" />
<filter class="org.apache.log4j.varia.LevelRangeFilter">
<param name="levelMin" value="INFO" />
</filter>
</appender>
<category name="com.ecyrd.jspwiki">
<priority value="ERROR">
</priority></category>
...
<root>
<priority value="INFO">
<appender-ref ref="CONSOLE">
<appender-ref ref="FILE">
<appender-ref ref="Sentry">
</appender-ref></appender-ref></appender-ref></priority></root>
</log4j:configuration>
After theses steps and a Liferay restart you should be done.
References
- [1] Sentry doc main page: http://sentry.readthedocs.org/
- [2] Liferay main product page: https://www.liferay.com/
- [3] Liferay log4j configuration wiki: http://www.liferay.com/es/community/wiki/-/wiki/Main/How+to+configure+the+logs+in+Liferay/
- [4] Liferay Log4j configuration file portal-log4j.xml: https://github.com/liferay/liferay-portal/blob/6.1.x/portal-impl/src/META-INF/portal-log4j.xml
- [5] Liferay Log4j DTD file for Liferay: https://github.com/liferay/liferay-portal/blob/6.1.x/portal-impl/src/META-INF/log4j.dtd
- [6] Nuxeo Log4j configuration example for Sentry: http://answers.nuxeo.com/questions/5914/how-to-use-third-party-log4j-appenders-in-nuxeo-tomcat-distribution
- [7] raven-java downloads: https://github.com/kencochrane/raven-java/downloads
- [8] raven-log4j Maven repository entry at mvnrepository.com: http://mvnrepository.com/artifact/net.kencochrane.raven/raven-log4j/4.1.2
No hay comentarios:
Publicar un comentario