java - log4j2 does not read spring boot property from correct configuration -
in log4j2.xml have following 2 properties:
<properties> <property name="log-path">logs</property> <property name="bootstrap.servers" value="${bundle:application:app.kafkabrokers}"></property> <property name="filename" value="${bundle:application:app.correctname}"></property>
and following 2 appenders:
<kafka name="kafka" topic="logaggregation" > <jsonlayout complete="false" compact="false" /> <patternlayout pattern="%date %message" /> <property name="bootstrap.servers">${bootstrap.servers}</property> </kafka> <rollingfile name="rollingfile" filename="${filename}" filepattern="logs/$${date:yyyy-mm}/app-%d{mm-dd-yyyy}-%i.log.gz"> <patternlayout> <pattern>%d %p %c{1.} [%t] %m%n</pattern> </patternlayout> <policies> <timebasedtriggeringpolicy /> <sizebasedtriggeringpolicy size="250 mb" /> </policies> </rollingfile>
kafkaappender reads property
bootstrap.servers
and rolling file reads property
filename
inside src/main/resources have following application.properties file:
app.kafkabrokers=localhost:9092
app.correctname=log.txt
inside folder jar located have application.properties file following contents:
app.kafkabrokers=localhost:9092 app.correctname=correct.log
now if run java -jar springboot jar log4j2 not property file resides inside directory jar file is, stated in spring documentation here
the fact if write following code in main class:
@postconstruct public void init() { system.out.println(env.getproperty("app.kafkabrokers") + " " + env.getproperty("app.correctname")); }
i see printed correct values such "correct.log" still log4j2 not new value , uses "log.txt"
what suspect log4j2 starts before spring pick correct application.properties file. ideas?
Comments
Post a Comment