Hi,
I am trying to use log4j to log messages to a file. Following is the entry in my web.xml
Below is spring servlet.xml content for log4j configCode:<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>
And below is my log4j.xml config file for redirecting messages to a fileCode:<bean id="AppLogger" class="org.springframework.beans.factory.config.CommonsLogFactoryBean"> <property name="logName" value="log" /> </bean>
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
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.Code:private static org.apache.log4j.Logger log = Logger.getLogger(MyClass.class);
Please help.


Reply With Quote
