Reputation: 1973
Say I have log4j2-spring.xml file with all the configuration of the appenders. There is a way to inject to the xml value from application.properties file?
My spring-log4j2.xml look like that:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<Appenders>
<Syslog name="ElkLogs" host="${logstash.host}" port="5002" protocol="UDP">
</Syslogs>
<Async name="AsyncElkLogs">
<AppenderRef ref="ElkLogs"
</Async>
</Appenders>
<Loggers>
<Root>
<AppenderRef ref="AsyncElkLogs"/>
</Root>
</Loggers>
</Configuration>
my application-dev.properties file:
logstash.host=elk-dev-1
my application-prod.properties file:
logstash.host=elk-prod-1
Upvotes: 2
Views: 4070
Reputation: 1973
I found another solution to my problem that decrease the coupling between the enviroments.
I created two configuration files, one for each enviroment with the names spring-log4j2-dev.xml
and spring-log4j2-prod.xml
and edit my application.properties
files to look like that:
application-dev.properties:
logging.config=classpath:spring-log4j2-dev.xml
application.properties:
logging.config=classpath:spring-log4j2-prod.xml
Upvotes: 1
Reputation: 1132
use below code
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>file:/relase/location1env/env1.properties</value>
<value>file:/relase/location2env/env2.properties</value>
</list>
Upvotes: 1