java - How to change the path of the log4j.properties file to a specific one? -


cheers,

i tried change file-path of log4j.properties /web-inf/classes /web-inf/lib. there way archive this? tried context-param set path did not archive goal.

<context-param>     <!-- specifiy <path> log4j.properties file superseed shipped version -->     <param-name>log4j_properties</param-name>     <param-value>/lib/log4j.properties</param-value>     </context-param> 

these outputs tomcat7-stdout.2015-04-01.log

----------> parent classloader: org.apache.catalina.loader.standardclassloader@2bb57fd1 . log4j: trying find [log4j.properties] using org.apache.catalina.loader.standardclassloader@2bb57fd1 class loader. log4j: trying find [log4j.properties] using classloader.getsystemresource(). log4j: not find resource: [null]. [el info]: 2015-04-01 09:05:07.764--serversession(598705739)--eclipselink, version: eclipse persistence services - 2.5.1.v20130918-f2b9fc5 [el info]: connection: 2015-04-01 09:05:08.246--serversession(598705739)--file:/c:/program files/apache software foundation/tomcat 7.0/webapps/archive/web-inf/lib/ot-ads.jar_administrationstore_url=jdbc:sqlserver://win-500s3sd3iqb:1433;databasename=ecr_user=ecr login successful started as_bizadmin api service log4j: trying find [log4j.xml] using context classloader webappclassloader   context: /dynamiclogservice   delegate: false   repositories: 

i tried use listener:

<listener> <listener-class>com.company.ecm.appsrv.logging.impl.loggingsetup</listener-class> </listener> 

but doesn't seem change anything.

loggingsetup.java:

package com.company.ecm.appsrv.logging.impl;  import java.io.ioexception; import java.io.inputstream; import java.util.properties;  import javax.servlet.servletcontext; import javax.servlet.servletcontextevent; import javax.servlet.servletcontextlistener;  import org.apache.log4j.logger; import org.apache.log4j.propertyconfigurator;  public class loggingsetup implements servletcontextlistener {     @override     public void contextdestroyed(servletcontextevent sce)     {         // nope     }      @override     public void contextinitialized(servletcontextevent sce)     {         servletcontext sctx = sce.getservletcontext();         properties props = new properties();          inputstream ins = null;          try         {             ins = sctx.getresourceasstream("/web-inf/lib/log4j.properties");             if(ins == null)                 throw new runtimeexception("could not find log4j properties");             props.load(ins);             string ctxname = sctx.getcontextpath().substring(1);             props.put("contextname", ctxname);             propertyconfigurator.configure(props);             logger.getrootlogger().info("loggin set up.");         }         catch(ioexception ex)         {             ex.printstacktrace();             sctx.log("could not setup logging", ex);         }                 {             if(ins != null)             {                 try { ins.close(); } catch(ioexception ex) { /* ignored */ }             }         }     } } 

complete web.xml:

<?xml version="1.0" encoding="utf-8"?> <!doctype web-app public "-//sun microsystems,  inc.//dtd web application 2.3//en" "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">  <web-app> <listener> <listener-class>com.company.ecm.appsrv.logging.impl.loggingsetup</listener-class> </listener>      <context-param>     <!-- specifiy <path> log4j.properties file superseed shipped version -->     <param-name>log4j_properties</param-name>     <param-value>/lib/log4j.properties</param-value>     </context-param>     <listener>         <listener-class>                 com.sun.xml.ws.transport.http.servlet.wsservletcontextlistener         </listener-class>     </listener>     <servlet>         <servlet-name>jaxws</servlet-name>         <servlet-class>             com.sun.xml.ws.transport.http.servlet.wsservlet         </servlet-class>         <load-on-startup>1</load-on-startup>     </servlet>     <servlet-mapping>         <servlet-name>jaxws</servlet-name>         <url-pattern>/services</url-pattern>     </servlet-mapping>     <session-config>         <session-timeout>120</session-timeout>     </session-config> </web-app> 

set following context param:

  <context-param>     <param-name>log4jconfiglocation</param-name>     <param-value>/web-inf/config/log4j/log4j.properties</param-value>   </context-param> 

don't forget add

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

in web.xml


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -