Log4j讀取配置文件並使用

  /** 設置配置路徑從環境變量讀取
    * PropertyConfigurator類加載.properties文件的配置
    * DOMConfigurator加載.xml文件的配置
    */
spa

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

相關文章
相關標籤/搜索