How to make a log register a property file whose name is a variable?

I am using http://logback.qos.ch/

I start my Java process with a parameter, for example, -Dproperties.url=myappproperties-production.propertiesor -Dproperties.url=myappproperties-development.properties, depending on the environment in which it is running.

Problem: how do I login to pick up my properties file?

If the name of the properties file is static, I would do ( works fine ):

<configuration>
    <property resource="myappproperties-development.properties" />
    (...)
</configuration>

But I need something dynamic ( this does not work ):

<configuration>
    <property resource="${properties.url}" />
    (...)
</configuration>
+5
source share
3 answers

The value of the resource file may be the property itself. In other words,

<configuration debug="true">
    <property resource="${properties.url}" />
    (...)
</configuration>

. BYW, debug <configuration> true, . ?

+4

, url ? .

-Dproperties.url="myappproperties-production.properties"

, .

, , , Amazon AMI Amazon Elastic Beanstalk -

0

This is the recommended Spring method:

<configuration>

    <springProfile name="local">
        <!-- configuration to be enabled when the "local" profile is active -->
        <property resource="application-local.properties" />
    </springProfile>

    <springProfile name="dev">
        <!-- configuration to be enabled when the "dev" profile is active -->
        <property resource="application-dev.properties" />
    </springProfile>

</configuration>

Reference docs: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-logging.html

0
source

All Articles