0

我现在正在与这个问题作斗争 3 天。我有一个带有 logback 和 lodash 依赖项的 Spring Boot 2.1.7 设置(非常基本)。

我正在尝试将我的 fat jar 部署在 Google Cloud Compute Engine 上的 docker 映像中。

我有以下 logback-spring.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>

  <include resource="org/springframework/boot/logging/logback/defaults.xml"/>

  <appender name="console" class="ch.qos.logback.core.ConsoleAppender">

    <springProfile name="default, local">
      <encoder>
        <pattern>${CONSOLE_LOG_PATTERN}</pattern>
        <charset>utf8</charset>
      </encoder>
    </springProfile>

    <springProfile name="test">
      <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
        <providers>
          <context/>
          <timestamp/>
          <version/>
          <logstashMarkers/>
          <mdc>
            <excludeMdcKeyName>X-B3-TraceId</excludeMdcKeyName>
            <excludeMdcKeyName>X-B3-SpanId</excludeMdcKeyName>
            <excludeMdcKeyName>X-B3-ParentSpanId</excludeMdcKeyName>
            <excludeMdcKeyName>X-Span-Export</excludeMdcKeyName>
          </mdc>
          <pattern>
            <pattern>
              {
              "app": "loyalty-api",
              "trace": "%X{X-B3-TraceId:-}",
              "span": "%X{X-B3-SpanId:-}",
              "spanParent": "%X{X-B3-ParentSpanId:-}"
              }
            </pattern>
          </pattern>
          <logLevel/>
          <loggerName/>
          <threadName/>
          <message/>
          <stackTrace/>
        </providers>
      </encoder>

    </springProfile>

  </appender>

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>
        %d{dd-MM-yyyy HH:mm:ss.SSS} %magenta([%thread]) %highlight(%-5level) %logger{36}.%M - %msg%n
      </pattern>
    </encoder>
  </appender>

  <appender name="asyncConsole" class="ch.qos.logback.classic.AsyncAppender">
    <appender-ref ref="console"/>
    <discardingThreshold>0</discardingThreshold>
  </appender>

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

</configuration>

没什么特别...

使用本地/测试/默认配置运行应用程序,但在我的本地计算机上,我能够启动应用程序 - 没有问题。

在 GCE 的 docker 映像中运行它时,我得到以下信息:

A 2019-09-27T17:08:13.881485575Z ERROR in ch.qos.logback.core.joran.spi.Interpreter@6:242 - no applicable action for [property], current ElementPath  is [[configuration][appender][property]]

A 2019-09-27T17:08:13.881419449Z CONSOLE_LOG_PATTERN_IS_UNDEFINEDCONSOLE_LOG_PATTERN_IS_UNDEFINEDjava.lang.IllegalStateException: Logback configuration error detected: 

完整日志:

A 2019-09-27T17:08:13.901892453Z Exception in thread "main" java.lang.reflect.InvocationTargetException

A 2019-09-27T17:08:13.894549994Z    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)

A 2019-09-27T17:08:13.894546714Z    at org.springframework.boot.loader.Launcher.launch(Launcher.java:51)

A 2019-09-27T17:08:13.894543454Z    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)

A 2019-09-27T17:08:13.894540114Z    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)

A 2019-09-27T17:08:13.894536754Z    at java.base/java.lang.reflect.Method.invoke(Method.java:567)

A 2019-09-27T17:08:13.894533279Z    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

A 2019-09-27T17:08:13.894529837Z    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

A 2019-09-27T17:08:13.894526131Z    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

A 2019-09-27T17:08:13.894522116Z    at pl.code.house.makro.mapa.backend.MakroMapaApp.main(MakroMapaApp.java:12)

A 2019-09-27T17:08:13.894502606Z    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1203)

A 2019-09-27T17:08:13.894499251Z    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1214)

A 2019-09-27T17:08:13.894495966Z    at org.springframework.boot.SpringApplication.run(SpringApplication.java:305)

A 2019-09-27T17:08:13.894492606Z    at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:341)

A 2019-09-27T17:08:13.894489175Z    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)

A 2019-09-27T17:08:13.894485713Z    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:76)

A 2019-09-27T17:08:13.894482301Z    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)

A 2019-09-27T17:08:13.894478740Z    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)

A 2019-09-27T17:08:13.894475312Z    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)

A 2019-09-27T17:08:13.894471886Z    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)

A 2019-09-27T17:08:13.894468440Z    at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:71)

A 2019-09-27T17:08:13.894464831Z    at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:114)

A 2019-09-27T17:08:13.894461408Z    at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:203)

A 2019-09-27T17:08:13.894458006Z    at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:140)

A 2019-09-27T17:08:13.894454510Z    at org.springframework.boot.SpringApplication.run(SpringApplication.java:305)

A 2019-09-27T17:08:13.894451107Z    at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:341)

A 2019-09-27T17:08:13.894447419Z    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)

A 2019-09-27T17:08:13.894443310Z    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:76)

A 2019-09-27T17:08:13.894439205Z    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)

A 2019-09-27T17:08:13.894423936Z    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)

A 2019-09-27T17:08:13.894420409Z    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)

A 2019-09-27T17:08:13.894416783Z    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)

A 2019-09-27T17:08:13.894395874Z    at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:203)

A 2019-09-27T17:08:13.894392446Z    at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:226)

A 2019-09-27T17:08:13.894389081Z    at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:264)

A 2019-09-27T17:08:13.894385687Z    at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:289)

A 2019-09-27T17:08:13.894382221Z    at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:118)

A 2019-09-27T17:08:13.894378816Z    at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:60)

A 2019-09-27T17:08:13.894375275Z    at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:73)

A 2019-09-27T17:08:13.894371460Z    at org.springframework.boot.logging.logback.LogbackLoggingSystem.reinitialize(LogbackLoggingSystem.java:220)

A 2019-09-27T17:08:13.894366905Z    at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:167)

A 2019-09-27T17:08:13.894360945Z ERROR in ch.qos.logback.core.joran.spi.Interpreter@6:242 - no applicable action for [property], current ElementPath  is [[configuration][appender][property]]

A 2019-09-27T17:08:13.894299813Z CONSOLE_LOG_PATTERN_IS_UNDEFINEDjava.lang.IllegalStateException: Logback configuration error detected: 

A 2019-09-27T17:08:13.881678113Z    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)

A 2019-09-27T17:08:13.881674309Z    at org.springframework.boot.loader.Launcher.launch(Launcher.java:51)

A 2019-09-27T17:08:13.881671010Z    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)

A 2019-09-27T17:08:13.881667402Z    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)

A 2019-09-27T17:08:13.881664061Z    at java.base/java.lang.reflect.Method.invoke(Method.java:567)

A 2019-09-27T17:08:13.881660595Z    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

A 2019-09-27T17:08:13.881656601Z    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

A 2019-09-27T17:08:13.881651627Z    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

A 2019-09-27T17:08:13.881648325Z    at pl.code.house.makro.mapa.backend.MakroMapaApp.main(MakroMapaApp.java:12)

A 2019-09-27T17:08:13.881645065Z    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1203)

A 2019-09-27T17:08:13.881641766Z    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1214)

A 2019-09-27T17:08:13.881638210Z    at org.springframework.boot.SpringApplication.run(SpringApplication.java:305)

A 2019-09-27T17:08:13.881620465Z    at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:341)

A 2019-09-27T17:08:13.881617075Z    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)

A 2019-09-27T17:08:13.881613664Z    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:76)

A 2019-09-27T17:08:13.881610244Z    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)

A 2019-09-27T17:08:13.881606644Z    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)

A 2019-09-27T17:08:13.881603255Z    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)

A 2019-09-27T17:08:13.881599842Z    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)

A 2019-09-27T17:08:13.881596423Z    at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:71)

A 2019-09-27T17:08:13.881592994Z    at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:114)

A 2019-09-27T17:08:13.881589547Z    at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:203)

A 2019-09-27T17:08:13.881586017Z    at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:140)

A 2019-09-27T17:08:13.881582696Z    at org.springframework.boot.SpringApplication.run(SpringApplication.java:305)

A 2019-09-27T17:08:13.881579333Z    at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:341)

A 2019-09-27T17:08:13.881575811Z    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)

A 2019-09-27T17:08:13.881571557Z    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:76)

A 2019-09-27T17:08:13.881568147Z    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)

A 2019-09-27T17:08:13.881564714Z    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)

A 2019-09-27T17:08:13.881561210Z    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)

A 2019-09-27T17:08:13.881557643Z    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)

A 2019-09-27T17:08:13.881553805Z    at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:203)

A 2019-09-27T17:08:13.881538511Z    at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:226)

A 2019-09-27T17:08:13.881514747Z    at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:264)

A 2019-09-27T17:08:13.881511151Z    at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:289)

A 2019-09-27T17:08:13.881507526Z    at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:118)

A 2019-09-27T17:08:13.881503591Z    at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:60)

A 2019-09-27T17:08:13.881499700Z    at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithConventions(AbstractLoggingSystem.java:73)

A 2019-09-27T17:08:13.881495999Z    at org.springframework.boot.logging.logback.LogbackLoggingSystem.reinitialize(LogbackLoggingSystem.java:220)

A 2019-09-27T17:08:13.881491479Z    at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:167)

A 2019-09-27T17:08:13.881485575Z ERROR in ch.qos.logback.core.joran.spi.Interpreter@6:242 - no applicable action for [property], current ElementPath  is [[configuration][appender][property]]

A 2019-09-27T17:08:13.881419449Z CONSOLE_LOG_PATTERN_IS_UNDEFINEDCONSOLE_LOG_PATTERN_IS_UNDEFINEDjava.lang.IllegalStateException: Logback configuration error detected: 

A 2019-09-27T17:08:11.735445525Z {"level":"INFO","logger_name":"org.springframework.core.KotlinDetector","message":"Kotlin reflection implementation not found at runtime, related features won't be available.","app":"makromapa-api","trace":"","span":"","spanParent":"","thread_name":"main","@timestamp":"2019-09-27T17:08:11.706Z","@version":"1"}

A 2019-09-27T17:08:11.588043416Z 

请问有人可以帮我解决这个问题吗?

4

1 回答 1

1

您是否在 docker 容器内的本地计算机上运行您的应用程序?

您是否尝试过${CONSOLE_LOG_PATTERN}用硬编码模式替换以检查它是否真的未定义(如错误所示)?

您还应该尝试在 Dockerfile 中明确设置模式。

于 2019-09-27T17:42:21.797 回答