web-dev-qa-db-fra.com

Configuration de la déconnexion de Spring Boot

J'essaie de configurer mon application de démarrage de printemps pour me connecter à un fichier pour la journée, donc je configure mon logback.xml comme ceci:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <include resource="org/springframework/boot/logging/logback/base.xml"/>

    <appender name="ROLLIN" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_FILE}</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">

            <!-- daily rollover -->
            <fileNamePattern>${LOG_FILE}.%d{yyyy-MM-dd}.log</fileNamePattern>

        </rollingPolicy>
    </appender>

    <root level="INFO">
        <appender-ref ref="ROLLIN" />
    </root>

    <logger name="org.springframework.web" level="INFO"/>
</configuration>

Donc, lorsque j'essaie d'exécuter mon application, j'ai eu cette erreur:

Exception in thread "main" Java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in ch.qos.logback.core.rolling.RollingFileAppender[ROLLIN] - No encoder set for the appender named "ROLLIN".
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.Java:151)
    at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.Java:71)
    at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.Java:49)
    at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.Java:106)
    at org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.Java:301)
    at org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.Java:253)
    at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.Java:225)
    at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.Java:201)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.Java:163)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.Java:136)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.Java:119)
    at org.springframework.boot.context.event.EventPublishingRunListener.publishEvent(EventPublishingRunListener.Java:111)
    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.Java:65)
    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.Java:54)
    at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.Java:330)
    at org.springframework.boot.SpringApplication.run(SpringApplication.Java:307)
    at org.springframework.boot.SpringApplication.run(SpringApplication.Java:1191)
    at org.springframework.boot.SpringApplication.run(SpringApplication.Java:1180)
    at br.com.lumera.Application.main(Application.Java:29)
:bootRun FAILED
10
Fabio Ebner

Comme le dit l'exception, aucun encodeur n'est défini. Essayez quelque chose comme

  <appender name="ROLLIN" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>logFile.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <!-- daily rollover -->
      <fileNamePattern>logFile.%d{yyyy-MM-dd}.log</fileNamePattern>

      <!-- keep 30 days' worth of history capped at 3GB total size -->
      <maxHistory>30</maxHistory>
      <totalSizeCap>3GB</totalSizeCap>

    </rollingPolicy>

    <encoder>
      <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n</pattern>
    </encoder>
  </appender>

Pour plus de détails, voir officiel documentation

9
sodik