Pages

Application specific logger using log4j in spring mvc and jboss 7.1

Hello friends,

In this tutorial i will show you how to create a logger for your web app without using default behavior which is provided by jboss AS7.

some time in production mode we want to separate logger for our web app or application specific logger and not want to use server default logger.

As we know that jboss also uses log4j for logging. So if we want to use our log4j specification for a app we have to override or disable the log4j default specification which is provided by the jboss.

Steps to implement the log4j for application specific

1. create log4j.properties file in side resource folder under src.


2. Define log4j propety inside log4j.properites




3. Now create a file "jboss-deployment-structure.xml" inside WEB-INF folder


 
4. Disable the log4j module for only this application by writing the content on "jboss-deployment-structure.xml"

sample of file-

<jboss-deployment-structure>

    <deployment>

        <exclusions>

            <module name="org.apache.log4j" />

        </exclusions>

    </deployment>

</jboss-deployment-structure>


5. Add the log4j jar into your lib folder under WEB-INF

6. Load the properties file by typing the content on your web.xml

<context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>/WEB-INF/classes/resources/log4j.properties</param-value>
    </context-param>
  
    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>

No comments:

Post a Comment