Log4j读取配置文件并使用

  /** 设置配置路径从环境变量读取
    * PropertyConfigurator类加载.properties文件的配置
    * DOMConfigurator加载.xml文件的配置
    */

public class LogInfo {
    static {
        try {
            PropertyConfigurator.configure(new FileInputStream("D:\\code\\first\\Log4JProject\\config\\log4j.properties"));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
    private static Logger logger=Logger.getLogger(LogInfo.class);
    public static void LogInformation(String info) {
        logger.info(info);
        logger.debug(info);
        logger.error(info);
    }
}

posted @ 2017-12-06 11:12  青春有多美  阅读(2302)  评论(0编辑  收藏  举报