Log4j and the difference slf4j

log4j: namely log for java; Java log 4 English homophone for four and
slf4j: simple log facade for java: simple log facade

Difference:
log4j logging is truly a product, there are a lot of products like this

slf4j is an adapter, we unified print the log method calls slf4j of our logs, logs and other specific methods can be ignored, so, when we changed the system a log source, you do not need to change the code:

for example:

假设日志系统A的info日志输出方法如下
A.message();
日志系统B的info日志输出方法如下
B.show();
log4j的info日志输出方法如下:
logger.getInfo()     //演示用  实际不是这个方法

slf4j的实现就是:
slf4j slf4j = new slf4j (A);
log.info();
这样我们用的就是日志系统A的方法,

现在假设我们的系统所在环境仅仅有log4j的日志输出环境,那么原来系统仅仅需要配置新的日志源即可
slf4j slf4j = new slf4j (log4j);

而不需要更改其他代码

Transfer: https://blog.csdn.net/qq_35794278/article/details/89599183

Published 274 original articles · won praise 144 · Views 7928

Guess you like

Origin blog.csdn.net/qq_44868502/article/details/103955244