Log4j 总结

log4j.rootLogger=INFO,A1

log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d{HH:mm:ss} %c{1} - %m%n


web应用 最好用一个servlet来手动加载log4j.properties, tomcat会在src下默认加载, 而其他应用服务器可能不会。


public class OnStartupServlet extends HttpServlet {

        @Override
        public void init() throws ServletException {
                // TODO Auto-generated method stub
                super.init();
                
                String contextPath = getServletContext().getRealPath("/");
                PropertyConfigurator.configure(contextPath + "/WEB-INF/conf/log4j.properties");
        }

}


在不同的操作系统中路径的/可能有不同, 需要用到java.io.File.separator
On UNIX systems the value of this
     * field is <code>'/'</code>; on Microsoft Windows systems it is <code>'\\'</code>.

public static String getCISBatchStatusConfigFile() {
		return AppContext.GetInstance().getContext().getRealPath("/")
				+ File.separator + WEB_INF + File.separator + "classes"
				+ File.separator + "CISBatchStatus.properties";
	}



你可能感兴趣的:(apache,tomcat,c,log4j,HP)