Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make logback read a properties file which name is a variable?

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

I am running my java process with a parameter for example -Dproperties.url=myappproperties-production.properties or -Dproperties.url=myappproperties-development.properties depending on the environemnt it is run in.

Problem: how to make logback pick up my properties file?

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

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

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

<configuration>
    <property resource="${properties.url}" />
    (...)
</configuration>
like image 488
Wojtek B. Avatar asked Oct 07 '22 11:10

Wojtek B.


1 Answers

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

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

should work. BYW, set the debug attribute of <configuration> element to true to see logback's internal messages on the console. Which version of logback are you using?

like image 157
Ceki Avatar answered Oct 12 '22 11:10

Ceki