Announcement Announcement Module
Collapse
No announcement yet.
Log4j issue - Logs going to console instead of file Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Log4j issue - Logs going to console instead of file

    Hi,

    I am trying to use log4j to log messages to a file. Following is the entry in my web.xml

    Code:
    <context-param>
      <param-name>log4jConfigLocation</param-name>
      <param-value>/WEB-INF/log4j.xml</param-value>
    </context-param>
    	
    <listener>
      <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>
    Below is spring servlet.xml content for log4j config

    Code:
    <bean id="AppLogger" class="org.springframework.beans.factory.config.CommonsLogFactoryBean">
    	<property name="logName" value="log" />
    </bean>
    And below is my log4j.xml config file for redirecting messages to a file

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
    <log4j:configuration>
      <appender name="file" class="org.apache.log4j.RollingFileAppender">
    	<param name="maxFileSize" value="100KB" />
    	<param name="maxBackupIndex" value="5" />
    	<param name="File" value="app.log" />
    	<param name="threshold" value="info"/>
    	<layout class="org.apache.log4j.PatternLayout">
    	    <param name="ConversionPattern" value="%d{ABSOLUTE} %5p %c{1}:%L - %m%n" />
    	</layout>
      </appender>
      <root>
        <priority value="debug"></priority>
        <appender-ref ref="file" />
      </root>
    </log4j:configuration>

    Now when I try to insert AppLogger bean as property into other beans and use that as logging object, its printing messages on console instead of the above mentioned file. Whereas if I use a new Log class as below
    Code:
    private static org.apache.log4j.Logger log = Logger.getLogger(MyClass.class);
    Then its sending messages to a log file. I guess I am missing something here, may be a link which will instruct Spring to redirect messages to the file. I am using Websphere App server.
    Please help.

  • #2
    Have you defined the Log4jConfigListener BEFORE the ContextLoaderListener in web.xml as per the JavaDoc for Log4jConfigListener?

    Comment

    Working...
    X