其他
从原理到实践彻底搞懂 Java 日志系统,再也不迷茫了!
二、日志框架的发展演变
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
log4j.rootLogger=trace, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %m%n
import org.apache.log4j.Logger;
public class Log4jTest {
public static void main(String[] args) {
Logger logger = Logger.getLogger(Log4jTest.class);
logger.info(logger.getClass().getName());
logger.info("apache日志框架log4j");
}
}
import java.util.logging.Logger;
public class JulTest {
public static void main(String[] args) {
Logger logger = Logger.getLogger(JulTest.class.getName());
//判断日志使用类型
logger.info(logger.getClass().getName());
logger.info("官方JDK日志框架Jul");
}
}
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class Log4jSif4jTest {
public static void main(String[] args) {
Logger logger = LoggerFactory.getLogger(Log4jSif4jTest.class);
logger.info(logger.getClass().getName());
logger.info("门面框架Sif4j整合Log4j输出");
}
}
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</dependency>
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class JCLJULTest {
public static void main(String[] args) {
Log log = LogFactory.getLog(JCLJULTest.class.getName());
log.info(log.getClass());
log.info("门面框架JCL整合JUL输出");
}
}
org.apache.commons.logging.Log = org.apache.commons.logging.impl.Jdk14Logger
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</dependency>
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class JCLJULTest {
public static void main(String[] args) {
Log log = LogFactory.getLog(JCLJULTest.class.getName());
log.info(log.getClass());
log.info("门面框架JCL整合JUL输出");
}
}
【源码解读】JDK1.8 中 ConcurrentHashMap 不支持空键值对源码剖析
面试官问:为什么 Java 线程没有 Running 状态?一下被问懵!
SpringBoot + Mybatis + Druid + PageHelper 实现多数据源并分页(附源码)
Intellij IDEA 中的各种调试代码技巧,轻松定位 Bug 问题(涵盖超全面)
MyBatis 真坑!Integer 类型赋值 0 ,当 != '' 时无法通过判断执行 SQL 语句
面试官问:Spring Boot 中实现通用 Auth 认证,有哪几种方式?