java - unable to generate a log file using log4j inspite everything is kept -


unable create log file.

web.xml

<?xml version="1.0" encoding="utf-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"          xmlns:xsi="http://www.w3.org/2001/xmlschema-instance"          xsi:schemalocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"          version="3.1">     <welcome-file-list>         <welcome-file>index.jsp</welcome-file>     </welcome-file-list>      <context-param>         <param-name>contextconfiglocation</param-name>         <param-value>/web-inf/applicationcontext.xml</param-value>     </context-param>      <context-param>         <param-name>log4j-config-location</param-name>         <param-value>/web-inf/log4j.xml</param-value>     </context-param>      <listener>         <listener-class>org.springframework.web.context.contextloaderlistener</listener-class>     </listener>     <listener>         <listener-class>org.springframework.web.util.log4jconfiglistener</listener-class>     </listener>     <servlet>         <servlet-name>dispatcher</servlet-name>         <servlet-class>org.springframework.web.servlet.dispatcherservlet</servlet-class>         <load-on-startup>1</load-on-startup>     </servlet>     <servlet-mapping>         <servlet-name>dispatcher</servlet-name>         <url-pattern>*.form</url-pattern>     </servlet-mapping>    </web-app> 

i have created log4j.xml in web-inf folder.

log4j.xml

<?xml version="1.0" encoding="utf-8" ?> <!doctype log4j:configuration system "log4j.dtd"> <log4j:configuration debug="true" xmlns:log4j='http://jakarta.apache.org/log4j/'>     <!-- appenders -->     <appender name="console" class="org.apache.log4j.consoleappender">         <param name="target" value="system.out" />         <param name="threshold" value="debug" />         <layout class="org.apache.log4j.patternlayout">             <param name="conversionpattern" value="%d %-5p %c{1}:%l %m %n" />         </layout>     </appender>      <appender name="fileappender" class="org.apache.log4j.rollingfileappender">         <param name="threshold" value="info" />         <param name="threshold" value="debug" />         <param name="maxfilesize" value="20mb" />         <param name="maxbackupindex" value="10" />         <param name="file" value="${catalina.home}/logs/mylog.log"/>         <param name="append" value="true" />         <layout class="org.apache.log4j.patternlayout">             <param name="conversionpattern" value="%d{yyyy-mm-dd hh:mm:ss} %-5p %c{1}:%l %m %n" />         </layout>     </appender>      <!--  3rdparty loggers -->     <logger name="org.springframework.core">         <level value="info" />     </logger>      <logger name="org.springframework.beans">         <level value="info" />     </logger>      <logger name="org.springframework.context">         <level value="info" />     </logger>      <logger name="org.springframework.web">         <level value="info" />     </logger>      <!-- root logger -->     <root>         <priority value="info"></priority>         <appender-ref ref="fileappender" />     </root>  </log4j:configuration> 

below folder project structure:

myproject     src     web       web-inf            lib            web.xml,applicationcontext.xml,log4j.xml,spring-config.xml... 

any suggestions helpful. have file inside web-inf folder , have given mapping in web.xml shown above, still when tomcat server started mylog.log file not creating. need add something? , 1 thing noticed log4jconfiglistenner depreciated class. have log4j-1.2.17.jar file in classpath. don't want keep log file in src folder, want in web-inf folder.

--edit-- have modified order of declaration of listeners in web.xml, still log file not generating.

<listener>            <listener-class>org.springframework.web.util.log4jconfiglistener</listener-class>         </listener> <listener>             <listener-class>org.springframework.web.context.contextloaderlistener</listener-class>         </listener> 

check order of listeners in web.xml on log4jconfiglistener javadoc specified:

this listener should registered before contextloaderlistener in web.xml when using custom log4j initialization.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -