我正在开发一个简单的桌面应用程序(不是webapp).
这是我的log4j.properties:
log4j.rootCategory=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L $$$$ %m%n
log4j.logger.org.springframework=ERROR,stdout
Run Code Online (Sandbox Code Playgroud)
如您所见,为了从控制台中消除Spring日志消息,我尝试了这个解决方案:
当我从我的代码调用log4j logger时,日志消息是根据上面指定的模式(这是好的).
然而,坏的部分是 - 我仍然从春天到达控制台DEBUG级别的消息......它们看起来像这里: 无法禁用日志消息
他们有不同的模式.好像他们忽略了我的设置.
我也尝试应用我在这里找到的建议:
https://spring.io/blog/2009/12/04/logging-dependencies-in-spring
在我的pom文件中:
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
而且没有SLF4J.如果我没有错,上述链接中提到此选项是有效选项.
我可能会在这里失踪什么?
输出-Dlog4j.debug = true
log4j: Trying to find [log4j.xml] using context classloader sun.misc.Launcher$AppClassLoader@172aa3f.
log4j: Trying to find [log4j.xml] using sun.misc.Launcher$AppClassLoader@172aa3f class loader.
log4j: Trying to find [log4j.xml] using ClassLoader.getSystemResource().
log4j: Trying to find [log4j.properties] using context classloader sun.misc.Launcher$AppClassLoader@172aa3f.
log4j: Using URL …Run Code Online (Sandbox Code Playgroud)