Log4j 使用代码加载配置文件

public class Log4jConfig{
    
    private static final Logger logger = Logger.getLogger(this.getName());
    
    public static void init() {
        logger.debug("Read the configuration file log4j.properties! ");
        try {
            String filepath = System.getProperty("user.dir") + "/config/log4j.properties";
            PropertyConfigurator.configure(filepath);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("Read the configuration file log4j.properties failed: " + e.getMessage());
        }
      } 
}

你可能感兴趣的:(Log4j 使用代码加载配置文件)