LOGBACK:没有为c.q.l.core.rolling.SizeAndTimeBasedRollingPolicy@1162810564提供上下文

时间:2019-12-25 17:39:22

标签: spring-boot spring-logback

我得到标题错误: LOGBACK:没有为c.q.l.core.rolling.SizeAndTimeBasedRollingPolicy@1162810564提供上下文

我在添加以下内容后得到了Spring Boot应用程序的最新版本: logging.file.name = src / main / resources / logs / spring advance.log 到正常工作的application.properties我只是不明白为什么,Logback是什么意思,如果这是一个错误/警告?以及如何解决?

如果我不将日志保存到日志文件中,而仅在控制台上打印,则不会出现此错误

这是我的完整application.properties:

spring.datasource.url=jdbc:mysql://localhost:3306/example? 
createDatabaseIfNotExist=true&serverTimezone=IST
spring.datasource.username=root
spring.datasource.password=1234
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

#Hibernate/Jpa Configuration:
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
#spring.jpa.properties.hibernate.show_sql:true
#spring.jpa.properties.hibernate.format_sql=true

#Log Configuration:
logging.file.name =src/main/resources/logs/spring advance.log
#•Show Sql Statement:
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type=TRACE
#•Show Sql Values:
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
logging.pattern.file=%d{yyyy-MM-dd HH:mm:ss} - %msg%n
logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} - %msg%n

#Server Port Configuration:
server.port=8080

2 个答案:

答案 0 :(得分:0)

您应包括xml配置文件并在application.properties中指向它

logging.config=classpath:config/logback-spring.xml

这是我使用的配置文件:

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
<configuration scan="true">
    <include resource="org/springframework/boot/logging/logback/base.xml"/>
    <logger name="javax.activation" level="WARN"/>
    <logger name="javax.mail" level="WARN"/>
    <logger name="javax.management.remote" level="WARN"/>
    <logger name="javax.xml.bind" level="WARN"/>
    <logger name="ch.qos.logback" level="WARN"/>
    <logger name="com.codahale.metrics" level="WARN"/>
    <logger name="com.ryantenney" level="WARN"/>
    <logger name="com.sun" level="WARN"/>
    <logger name="com.zaxxer" level="WARN"/>
    <logger name="io.undertow" level="WARN"/>
    <logger name="io.undertow.websockets.jsr" level="ERROR"/>
    <logger name="org.ehcache" level="WARN"/>
    <logger name="org.apache" level="WARN"/>
    <logger name="org.apache.catalina.startup.DigesterFactory" level="OFF"/>
    <logger name="org.bson" level="WARN"/>
    <logger name="org.hibernate.validator" level="WARN"/>
    <logger name="org.hibernate" level="WARN"/>
    <logger name="org.hibernate.ejb.HibernatePersistence" level="OFF"/>
    <logger name="org.springframework" level="WARN"/>
    <logger name="org.springframework.web" level="WARN"/>
    <logger name="org.springframework.security" level="WARN"/>
    <logger name="org.springframework.cache" level="WARN"/>
    <logger name="org.thymeleaf" level="WARN"/>
    <logger name="org.xnio" level="WARN"/>
    <logger name="springfox" level="WARN"/>
    <logger name="sun.rmi" level="WARN"/>
    <logger name="liquibase" level="WARN"/>
    <logger name="LiquibaseSchemaResolver" level="INFO"/>
    <logger name="sun.rmi.transport" level="WARN"/>

    <!-- https://logback.qos.ch/manual/configuration.html#shutdownHook and https://jira.qos.ch/browse/LOGBACK-1090 -->
    <shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook"/>

    <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
        <resetJUL>true</resetJUL>
    </contextListener>

</configuration>

答案 1 :(得分:0)

在resources文件夹中添加logback-spring.xml对我来说解决了这个问题。 XML文件的内容可以在https://docs.spring.io/spring-boot/docs/1.5.x/reference/html/howto-logging.html上找到。