gpt4 book ai didi

Override logback appender-ref from CLI(覆盖登录附加器-来自CLI的引用)

转载 作者:bug小助手 更新时间:2023-10-25 13:35:39 26 4
gpt4 key购买 nike



I have a logback configuration that for prod and int profiles uses rsyslog appender

我有一个针对prod和int配置文件的Logback配置,它使用rsyslog附加器


<root level="info">

<springProfile name="prod,int">
<appender-ref ref="SYSLOG7"/>
</springProfile>
<springProfile name="default">
<appender-ref ref="FILE"/>
<appender-ref ref="STDOUT"/>
</springProfile>
</root>

This configuration is distributed through hundreds of applications. I need to change it in all applications to stdout. I would be grateful if there was an option to override it in common dockerfile entrypoint (so preferably using some env variable/CLI parameter). Is there something like this?

此配置通过数百个应用程序分发。我需要在所有应用程序中将其更改为stdout。如果有一个选项可以在公共dockerfile入口点中覆盖它(因此最好使用某个环境变量/CLI参数),我将不胜感激。有这样的东西吗?


更多回答
优秀答案推荐

ENV variable/CLI parameter:

环境变量/CLI参数:


docker run -e LOG_APPENDER=STDOUT your-image-name

Note: When you run your Docker container, you can pass an environment variable to specify the appender.

注意:运行Docker容器时,可以传递一个环境变量来指定附加器。


If you have a common Docker entrypoint script that's used across all your applications, you can include logic to read the LOG_APPENDER environment variable and update the Logback configuration dynamically before starting your application. This way, you don't need to modify each application's Dockerfile.

如果您有一个跨所有应用程序使用的通用Docker入口点脚本,则可以包括逻辑来读取LOG_APPENDER环境变量,并在启动应用程序之前动态更新Logback配置。这样,您不需要修改每个应用程序的Dockerfile。


Here's a simplified example of what your entrypoint script might look like:

下面是您的入口点脚本的简化示例:


#!/bin/sh

# Check if LOG_APPENDER is set, and if so, update the Logback config
if [ -n "$LOG_APPENDER" ]; then
sed -i 's|<appender-ref ref=".*"/>|<appender-ref ref="'$LOG_APPENDER'"/>|' /path/to/your/logback.xml
fi

# Start your application
exec java -jar your-app.jar



更多回答

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com