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);
    }
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM