jar包:
log4j-api-2.10.0.jar
log4j-core-2.10.10.jar
log4j-1.2-api-2.10.0.jar
log4j-slf4j-impl-2.10.10.jar
slf4j-api-1.7.25.jar
使用:
public class AAA{
static logger LOGGER=MyLOG.getLog(AAA.class);
public static void main(String[] args) {
LOGGER.info("日志信息")
} }
public class MyLOG{ public static Logger getLog(Class<?> clazz){ return LoggerFactory.getLogger(clazz.getName());
}
public static Logger getLog(String name){ return LoggerFactory.getLogger(name);
} }
log4j2.xml配置:
name="P_NAME",自己定义
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="OFF" monitorInterval="30">
<properties>
<!--设置日志在硬盘上输出的目录-->
<property name="P_NAME">AAA</property>
<property name="LOG_HOME">D:/logger/${P_NAME}</property>
</properties>
https://blog.csdn.net/shiyong1949/article/details/54666992
https://blog.csdn.net/zheng0518/article/details/69558893