Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Liferay Integaration with Log4j

    • 0
    • 3
    • 3
    • 1
    • 0
    • 0
    • 0
    • 0
    • 1.02k
    Comment on it

    Liferay+Log4j:- This blog will show you how you can implement logging in Liferay with Log4j. By using this you can use the custom logging using Log4j in Lifeary. To make this possible follow the below steps:-
    1. Create log4j.xml and log4j.dtd file inside the src folder of your Portlet.

    DentalNote-home-portlet/docroot/WEB-INF/src/

    I have taken the log4j.dtd from the liferay portal source.

    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="${catalina.base}/logs/dentalNote.%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>
    

    2. Modify the liferay-plugin-package.properties. add the below code at bottom.

    portal-dependency-jars=\
            log4j.jar,\
            log4j-extras.jar
    

    3. At last you need to setup your logger in your class.

    private static Logger logger = Logger.getLogger(PatientSearch.class);
    logger.info("Hello Controller");
    

    NOTE:- See your log file inside the liferay-portal-6.2-ce-ga2/tomcat/logs folder.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: