zoukankan      html  css  js  c++  java
  • log4j配置

    在src目录下增加 

    log4j.properties:

    log4j.appender.logFile=org.apache.log4j.FileAppender
    log4j.appender.logFile.Threshold=DEBUG 
    log4j.appender.logFile.ImmediateFlush=true
    log4j.appender.logFile.Append=true
    log4j.appender.logFile.File=F:/Workspaces/logs/log.log4j
    log4j.appender.logFile.layout=org.apache.log4j.PatternLayout
    log4j.appender.logFile.layout.ConversionPattern=[%-5p] %d(%r) --> [%t] %l: %m %x %n

    package Acton下

    Action.java:

    package Action;
    
    public interface Action {
               public String execute(String str);
    }
    
    LowerAction.java:
    
    package Action;
    
    public class LowerAction implements Action {
    
    	private String message;
    
    	public String getMessage() {
    		return message;
    	}
    
    	public void setMessage(String string) {
    		message = string;
    	}
    
    	public String execute(String str) {
    		return (getMessage() + str).toLowerCase();
    	}
    }
    

    UpperAction.java:

    package Action;
    
    
    public class UpperAction implements Action {
    	private String message;
    
    	public String getMessage() {
    		return message;
    	}
    	public void setMessage(String string) {
    		message = string;
    	}
    
    	public String execute(String str) {
    		return ((getMessage() + str).toUpperCase());
    	}
    }

    Test.java:

    package Action;
    
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.springframework.beans.factory.BeanFactory;
    import org.springframework.beans.factory.xml.XmlBeanFactory;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    import org.springframework.core.io.ClassPathResource;
    import org.springframework.core.io.Resource;
    
    public class Test {
    	public static Log log = LogFactory.getLog("Test");
    
    	public static void main(String Args[]) {
    		log.info("Start...");
    		// String[] locations = { "beans.xml" };
    		/*ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
    		Action action = (Action) ctx.getBean("beanID");
    		System.out.println(action.execute("  Joson"));*/
    		Resource resource=new ClassPathResource("beans.xml");
    		@SuppressWarnings("deprecation")
    		BeanFactory factory=new XmlBeanFactory(resource);
    		Action action=(Action)factory.getBean("beanID");
    		System.out.println(action.execute("  The new future"));
    		log.info("End...");
    	}
    
    }
    

    beans.xml:

    <?xml version="1.0" encoding="UTF-8" ?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans 
     http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
        <description>Spring Quick Start</description>
        <bean id="beanID" class="Action.LowerAction">
            <property name="message" value="hello"/>
            </bean>
    </beans>

    加载Spring和log4j的jar包


  • 相关阅读:
    flask 源码专题(七):threading.local和高级
    flask 源码专题(六):session处理机制
    flask 源码专题(五):SqlAlchemy 中操作数据库时session和scoped_session的区别
    flask 源码专题(四):wtforms Form实例化流程以及csrf验证
    flask 源码专题(三):请求上下文和应用上下文入栈与出栈
    python 追踪函数调用
    flask 源码专题(一):app.run()的背后
    flask 源码专题(二):请求上下文与全文上下文
    边框间距 | border-spacing (Miscellaneous Level 2)
    边框样式属性 | border-top-style (Backgrounds & Borders)
  • 原文地址:https://www.cnblogs.com/JAYIT/p/4057517.html
Copyright © 2011-2022 走看看