[英]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.