Reputation: 1651
I have Spring Boot application which internally uses libraries with log4j logging.
I added inside pom.xml (to attach log4j entries to my logback logs):
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</dependency>
According http://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html#howto-configure-logback-for-logging-fileonly I added custom logback-spring.xml which should disable console log output:
<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>
The problem is after:
java -jar my-app.jar &
baner.txt and following warning are still written to console:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: 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: How to disable console logs entirely? Q2: How to attach log4j log to logback file output?
Upvotes: 1
Views: 2174
Reputation: 28136
According to the comment, just 1 question left. If you need to disable banner, there are a number of ways. You can do it via application.properties
file like:
spring.main.banner-mode=off
Or via application.yml
as:
spring:
main:
banner-mode: "off"
Or even in your sources:
public static void main(String... args) {
SpringApplication application = new SpringApplication(SomeSpringConfiguration.class);
application.setBannerMode(Banner.Mode.OFF);
application.run(args);
}
Upvotes: 1
Reputation: 1651
Solution to log4j WARN was to exclude transitive dependencies from my internal libraries.
Banner is written to console by default, so we have to set:
spring.main.banner-mode=log
https://github.com/spring-projects/spring-boot/issues/4001
Upvotes: 1