[英]Define Custom Log Level in Configuration file and Access them is Java Code, Log4J2
我想在配置文件中定義自定義日志級別,如下所示
<CustomLevels>
<CustomLevel name="DIAG" intLevel="350" />
<CustomLevel name="NOTICE" intLevel="450" />
<CustomLevel name="VERBOSE" intLevel="550" />
</CustomLevels>
我想像這樣用Java代碼訪問它們
Level diag = // get level defined in configuration
// and use them like this
logger.log(diag, "message");
// and then this 'message' is printed in the appender with thresholdfilter as diag
然后將閾值過濾器與配置文件中定義的級別進行比較,在追加器上...
這可能嗎? 如果是,那又如何?
定義自定義級別,如下所示:
public static final Level DIAG = Level.forName("DIAG", 350)
因此,您所需要的只是從配置文件中讀取這些級別(在啟動時),並將它們分配給一些靜態變量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.