Reputation: 31925
I am new to SpringBoot Project, I am trying to configure logback-spring.xml
Logging Dependencies in my project pom.xml
file:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
</dependency>
Logging Configuration in application.proerties
:
logging.config=classpath:logback-spring.xml
logging.level.org.springframework.web=DEBUG
logging.level.org.hibernate=ERROR
When I run the executable war, it throws below exceptions:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/target/rentacoder.war!/WEB-INF/lib/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/target/rentacoder.war!/WEB-INF/lib/slf4j-simple-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
log4j:WARN Continuable parsing error 2 and column 16
log4j:WARN Document root element "configuration", must match DOCTYPE root "null".
log4j:WARN Continuable parsing error 2 and column 16
log4j:WARN Document is invalid: no grammar found.
log4j:WARN The <configuration> element has been deprecated.
log4j:WARN Use the <log4j:configuration> element instead.
log4j:WARN Unrecognized element include
log4j:ERROR Could not create an Appender. Reported error follows.
java.lang.ClassNotFoundException: ch.qos.logback.core.FileAppender
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at org.springframework.boot.loader.LaunchedURLClassLoader.doLoadClass(LaunchedURLClassLoader.java:178)
at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:142)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
My logback-spring.xml
is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<logger name="org.springframework.web" level="DEBUG"/>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
<file>myApp.log</file>
<encoder>
<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
</encoder>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>
</encoder>
</appender>
<logger name="org.apache.velocity" level="OFF" />
<root level="INFO">
<appender-ref ref="FILE" />
<appender-ref ref="STDOUT" />
</root>
</configuration>
Can someone shed some light on this? How can I fix it?
Upvotes: 0
Views: 1409
Reputation: 116301
There are a couple of problems.
Firstly, to use logback-spring.xml
to configure your logging, you need to be using Logback yet you've excluded spring-boot-starter-logging
which uses Logback in favour of spring-boot-starter-log4j
which uses Log4j. If you want to use logback-spring.xml
you should remove the exclusion from your pom.
Secondly, SLF4J: Found binding in [jar:file:/target/rentacoder.war!/WEB-INF/lib/slf4j-simple-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class]
means that you also have slf4j-simple
on the class path. I can't tell where it's coming from given the information you've provided but you need to remove it from your dependencies. You can use mvn dependency:tree
to help you to determine where it's coming from and remove/exclude it as appropriate.
Upvotes: 1