我将 slf4j 与 log4j 结合使用。我的 POM 依赖项如下所示 -
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
如 SLF4J FAQ 中所述
The SLF4J API supports parametrization in the presence of an exception, assuming the exception is the last parameter.
有没有办法确定异常是否作为最后一个参数传递给所有记录器的方法调用(如 error
、info
)?
最佳答案
没有简单的方法可以在编译时甚至运行时进行这种检查。
但是您可以使用 FindBugs 的组合和 findbugs-slf4j使用 SLF4J_PLACE_HOLDER_MISMATCH
进行静态检查的插件和 SLF4J_FORMAT_SHOULD_BE_CONST
。
关于java - Log4j 验证异常是否作为最后一个参数传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47633702/