2

There is a spring-boot (2.0.0.RELEASE) application as part of the spring-cloud (Finchley.M9) cluster.
On startup, it always print following line:

CONSOLE_LOG_PATTERN_IS_UNDEFINEDCONSOLE_LOG_PATTERN_IS_UNDEFINEDCONSOLE_LOG_PATTERN_IS_UNDEFINED


(following are the configuration)

application.yml:

## spring-boot configuration,

# logging
logging:
  file: "log/hello.log"
  pattern:
    console: "[%d{yyyy-MM-dd HH:mm:ss.SSS}] %-5level [%t] [%logger - %line]: %m%n"
    file: "[%d{yyyy-MM-dd HH:mm:ss.SSS}] %-5level [%t] [%logger - %line]: %m%n"
  level:
    root: INFO

spring:
  application:
    name: eric-sc-hello

server:
  port: 9191

management:
  endpoints:
    web:
      exposure:
    include: "*"

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/

eric-sc-hello:
  ribbon:
    eureka:
      enabled: false
    listOfServers: localhost:9191,localhost:9192,localhost:9193
    ServerListRefreshInterval: 15000

logback-spring.xml:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <charset>UTF-8</charset>
      <Pattern>${CONSOLE_LOG_PATTERN}</Pattern>
    </encoder>
  </appender>
  <appender name="FILE"
    class="ch.qos.logback.core.rolling.RollingFileAppender">
    <encoder>
      <pattern>${FILE_LOG_PATTERN}</pattern>
    </encoder>
    <file>${LOG_FILE}</file>
    <rollingPolicy
      class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
      <fileNamePattern>${LOG_FILE}.%i</fileNamePattern>
      <minIndex>1</minIndex>
      <maxIndex>10</maxIndex>
    </rollingPolicy>
    <triggeringPolicy
      class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
      <MaxFileSize>10MB</MaxFileSize>
    </triggeringPolicy>
  </appender>

  <root level="INFO">
    <appender-ref ref="CONSOLE" />
    <appender-ref ref="FILE" />
  </root>
</configuration>

The warning says CONSOLE_LOG_PATTERN is undefined for 3 times.

But logging.pattern.console is defined in application.yml, and the log lines in console is printed in the specified format.

So, why the warning pop-up, and how can I remove it?


@Update

I already found some solutions, and had added an answer here: https://stackoverflow.com/a/62846599/

Eric
  • 22,183
  • 20
  • 145
  • 196

3 Answers3

1

I cannot explain why it's happening, but if you set logging.config property to smth else e.g. my-project-logback.xml and don't use logback-spring.xml name - everything is working without CONSOLE_LOG_PATTERN_IS_UNDEFINED message. Documentation allows to do this.

From Spring Boot Logging documentation:

Because the standard logback.xml configuration file is loaded too early, you cannot use extensions in it. You need to either use logback-spring.xml or define a logging.config property.

nmyk
  • 1,582
  • 1
  • 8
  • 20
1

My answer is not directly related to your question but I was seeing similar problems using the default org/springframework/boot/logging/logback/console-appender.xml appender in Spring Boot 2.x.

So instead of defining the logging.pattern.console in your application config you could directly include the CONSOLE_LOG_PATTERN definition in the logback-spring.xml configuration.

e.g. the default config would be included like this.

<configuration>
 <include resource="org/springframework/boot/logging/logback/defaults.xml">
...
Saurabh
  • 882
  • 1
  • 5
  • 16
HannesB
  • 89
  • 7
0

You need to define Spring properties explicitly in logback-spring.xml like so:

    <configuration>
        <springProperty name="CONSOLE_LOG_PATTERN" source="logging.pattern.file"/>

      .... rest of configuration ....
AlexGera
  • 756
  • 9
  • 19