差異處
這裏顯示兩個版本的差異處。
Both sides previous revision 前次修改 下次修改 | 前次修改 | ||
java:log4j2:mdc [2022/04/10 13:19] tony |
java:log4j2:mdc [2023/06/25 09:48] (目前版本) |
||
---|---|---|---|
行 22: | 行 22: | ||
System.setProperty("log4j2.isThreadContextMapInheritable","true"); | System.setProperty("log4j2.isThreadContextMapInheritable","true"); | ||
</code> | </code> | ||
+ | 最後要再提醒各位,用完MDC要記得清除放進去的資料,否則是會造成memory leak的。 | ||
===== Migrate from log4j1 ===== | ===== Migrate from log4j1 ===== | ||
- | 設定檔格式的部分沒有差別,可以沿用,source code部分則是用ThreadContext取代MDC,可以參考log4j2的[[https://github.com/apache/logging-log4j2/blob/f72100df0decc9bda96b4d769822c4e48b2848fc/log4j-1.2-api/src/main/java/org/apache/log4j/MDC.java|source code]]做對應的替換。 | + | 設定檔格式的部分沒有差別,可以沿用,source code部分則是用ThreadContext取代MDC,可以參考log4j2的[[https://github.com/apache/logging-log4j2/blob/f72100df0decc9bda96b4d769822c4e48b2848fc/log4j-1.2-api/src/main/java/org/apache/log4j/MDC.java|source code]]做對應的替換。\\ |
+ | 另外一個選擇是直接使用slf4j的MDC: [[https://codertw.com/%E4%BC%BA%E6%9C%8D%E5%99%A8/133627/|link]],讓它由binding決定實做,避免了實做相依。 | ||
===== Refernece ===== | ===== Refernece ===== | ||
* [[https://stackoverflow.com/questions/49188105/log4j2-isthreadcontextmapinheritable-property-usage|log4j2 isThreadContextMapInheritable property usage]] | * [[https://stackoverflow.com/questions/49188105/log4j2-isthreadcontextmapinheritable-property-usage|log4j2 isThreadContextMapInheritable property usage]] |