Cra*_*ro7 2 java ubuntu logback spring-boot
我有一个带有 Logback 的 Springboot 应用程序。这场战争正在 Docker 容器中的 Liberty Web 服务器中运行
版本:Springboot 2.5.3 Logback 1.2.3
我看到一个奇怪的行为,如果我在 Mac 或 Redhat 上运行此容器,应用程序会正常启动并按预期记录。但是,当在 Ubuntu 中运行相同的 docker 容器时,我从 Logback 的 Joran 解释器中看到以下错误:
...
08:07:53,308 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.springframework] to WARN
08:07:53,308 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [org.hibernate] to WARN
08:07:53,308 |-INFO in ch.qos.logback.classic.joran.action.LoggerAction - Setting level of logger [springfox] to WARN
08:07:53,313 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@88:32 - no applicable action for [springProfile], current ElementPath is [[configuration][springProfile]]
08:07:53,313 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@89:51 - no applicable action for [root], current ElementPath is [[configuration][springProfile][root]]
08:07:53,314 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@90:73 - no applicable action for [appender-ref], current ElementPath is [[configuration][springProfile][root][appender-ref]]
08:07:53,314 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
08:07:53,314 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@5b3de2a2 - Registering current configuration as safe fallback point
[err] Logging system failed to initialize using configuration from '/logback-spring.xml'
[err] java.lang.IllegalStateException: Logback configuration error detected:
ERROR in ch.qos.logback.core.joran.spi.Interpreter@88:32 - no applicable action for [springProfile], current ElementPath is [[configuration][springProfile]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@89:51 - no applicable action for [root], current ElementPath is [[configuration][springProfile][root]]
ERROR in ch.qos.logback.core.joran.spi.Interpreter@90:73 - no applicable action for [appender-ref], current ElementPath is [[configuration][springProfile][root][appender-ref]]
[err] at org.springframework.boot.logging.logback.LogbackLoggingSystem.loadConfiguration(LogbackLoggingSystem.java:179)
[err] at org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSpecificConfig(AbstractLoggingSystem.java:66)
[err] at org.springframework.boot.logging.AbstractLoggingSystem.initialize(AbstractLoggingSystem.java:57)
[err] at org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:132)
[err] at org.springframework.boot.context.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:316)
[err] at org.springframework.boot.context.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:282)
[err] at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:240)
[err] at org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:216)
[err] at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
[err] at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
[err] at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
[err] at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
[err] at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:82)
[err] at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:63)
[err] at org.springframework.boot.SpringApplicationRunListeners$$Lambda$71/0x000000006c31f840.accept(Unknown Source)
[err] at java.util.ArrayList.forEach(ArrayList.java:1270)
[err] at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:117)
[err] at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:111)
[err] at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:62)
[err] at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:374)
[err] at org.springframework.boot.SpringApplication.run(SpringApplication.java:332)
[err] at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:175)
[err] at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:155)
[err] at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:97)
[err] at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:174)
[err] at com.ibm.ws.webcontainer.webapp.WebApp.initializeServletContainerInitializers(WebApp.java:2550)
[err] at [internal classes]
[err] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1160)
[err] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
[err] at java.lang.Thread.run(Thread.java:822)
Run Code Online (Sandbox Code Playgroud)
这是我的日志配置:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="console-json"
class="ch.qos.logback.core.ConsoleAppender">
<encoder name="LoggingEventCompositeJsonEncoder"
class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<timestamp/>
<version/>
<message/>
<loggerName>
<shortenedLoggerNameLength>20
</shortenedLoggerNameLength>
</loggerName>
<threadName/>
<logLevel/>
<logLevelValue/>
<callerData>
<fieldName>caller</fieldName>
<classFieldName>class</classFieldName>
<methodFieldName>method</methodFieldName>
<fileFieldName>file</fileFieldName>
<lineFieldName>line</lineFieldName>
</callerData>
<stackTrace>
<throwableConverter
class="net.logstash.logback.stacktrace.ShortenedThrowableConverter">
<maxDepthPerThrowable>100</maxDepthPerThrowable>
<maxLength>10000</maxLength>
<shortenedClassNameLength>30
</shortenedClassNameLength>
<rootCauseFirst>true</rootCauseFirst>
<inlineHash>true</inlineHash>
</throwableConverter>
</stackTrace>
<stackHash/>
<jsonMessage/>
<mdc/>
<contextMap/>
<tags/>
<logstashMarkers/>
<arguments>
<includeNonStructuredArguments>true
</includeNonStructuredArguments>
<nonStructuredArgumentsFieldPrefix>prefix
</nonStructuredArgumentsFieldPrefix>
</arguments>
</providers>
</encoder>
</appender>
<logger name="org.springframework" level="WARN"/>
<logger name="org.hibernate" level="WARN"/>
<logger name="springfox" level="WARN"/>
<springProfile name="prod">
<root level="${logback_root_level:-INFO}">
<appender-ref ref="${logback_root_appender:-console-json}"/>
</root>
</springProfile>
<springProfile name="minimal">
<root level="${logback_root_level:-WARN}">
<appender-ref ref="${logback_root_appender:-console-json}"/>
</root>
</springProfile>
</configuration>
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏!
小智 5
来自 Spring Boot文档:
\n\n\n由于标准 logback.xml 配置文件加载得太早,因此您无法在其中使用扩展。您需要使用\nlogback-spring.xml 或定义logging.config 属性。
\n这些扩展不能与 Logback\xe2\x80\x99s 配置扫描一起使用。\n如果您尝试这样做,对配置文件进行更改\n会导致类似于记录以下内容之一的错误:
\n
ERROR in ch.qos.logback.core.joran.spi.Interpreter@4:71 - no applicable action for [springProperty], current ElementPath is [[configuration][springProperty]]\nERROR in ch.qos.logback.core.joran.spi.Interpreter@4:71 - no applicable action for [springProfile], current ElementPath is [[configuration][springProfile]]\nRun Code Online (Sandbox Code Playgroud)\n然后,由于您使用的是 Spring Boots 的扩展标记,因此您需要将文件命名为logback-spring.xml,以便在正确的时间加载它。
| 归档时间: |
|
| 查看次数: |
3453 次 |
| 最近记录: |