【发布时间】:2016-12-02 11:25:37
【问题描述】:
我有 Spring Boot 应用程序,它在内部使用带有 log4j 日志记录的库。
我在 pom.xml 中添加了(将 log4j 条目附加到我的 logback 日志中):
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</dependency>
根据http://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html#howto-configure-logback-for-logging-fileonly,我添加了自定义 logback-spring.xml,它应该禁用控制台日志输出:
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<property name="LOG_FILE" value="${LOG_FILE:-${LOG_PATH:-${LOG_TEMP:-${java.io.tmpdir:-/tmp}}/}spring.log}"/>
<include resource="org/springframework/boot/logging/logback/file-appender.xml" />
<root level="INFO">
<appender-ref ref="FILE" />
</root>
</configuration>
问题出在:
java -jar my-app.jar &
baner.txt 和以下警告仍会写入控制台:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.4.2.RELEASE)
log4j:WARN No appenders could be found for logger (package.hidden).
log4j:WARN Please initialize the log4j system properly.
Q1:如何完全禁用控制台日志? Q2:如何将 log4j 日志附加到 logback 文件输出?
【问题讨论】:
-
好的,我从我的库中排除了 log4j,并且没有显示警告。但是baner仍然可见。
标签: spring-boot log4j logback executable-jar