log(一)——MDC入门
生活随笔
收集整理的這篇文章主要介紹了
log(一)——MDC入门
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
?1.MDC是什么
先來一段原版注釋,
/*** This class hides and serves as a substitute for the underlying logging* system's MDC implementation.* * <p>* If the underlying logging system offers MDC functionality, then SLF4J's MDC,* i.e. this class, will delegate to the underlying system's MDC. Note that at* this time, only two logging systems, namely log4j and logback, offer MDC* functionality. For java.util.logging which does not support MDC,* {@link BasicMDCAdapter} will be used. For other systems, i.e slf4j-simple* and slf4j-nop, {@link NOPMDCAdapter} will be used.** <p>* Thus, as a SLF4J user, you can take advantage of MDC in the presence of log4j,* logback, or java.util.logging, but without forcing these systems as* dependencies upon your users.* * <p>* For more information on MDC please see the <a* href="http://logback.qos.ch/manual/mdc.html">chapter on MDC</a> in the* logback manual.* * <p>* Please note that all methods in this class are static.* * @author Ceki Gülcü* @since 1.4.1*/這是MDC類上的注釋,但是沒有講這個是干什么的。具體的內容在有一個頁面:
Chapter 8: Mapped Diagnostic Context
簡單來說就是日志的增強功能,如果配置了MDC,并添加了相應的key value,就會在打日志的時候把key對應的value打印出來。
內部是用ThreadLocal來實現的,可以攜帶當前線程的context信息。
2.MDCAdapter——LogbackMDCAdapter
MDC中包裝了一個MDCAdapter,這是一個接口,不同的log包有自己對應的實現。對于不支持MDC的包,比如java.util.logging,使用默認的BasicMDCAdapter,slf4j-nop有NOPMDCAdapter。
這里說的實現是LogbackMDCAdapter。
總結
以上是生活随笔為你收集整理的log(一)——MDC入门的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: docker及k8s容器面试精华汇总(一
- 下一篇: echerts 去掉饼形图的须子