3

我收到标题错误:LOGBACK: No context given for cqlcore.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
4

2 回答 2

1

您应该包含 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>
于 2019-12-27T09:01:03.240 回答
1

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

于 2020-03-27T20:08:36.093 回答