I setup my spring-boot app to fetch log4j2 configuration file from config server. But lookups are not working. If I place the log configuration file under resources folder it works fine. Also monitor interval is not working if the file is on config server.
Example of my configuration file:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn" monitorInterval="60">
<Appenders>
<Console name="ConsoleJSONAppender" target="SYSTEM_OUT">
<JSONLayout complete="false" compact="false" eventEol="true" properties="false" stacktraceAsString="true">
<KeyValuePair key="correlation-id" value="${ctx:CORRELATION_ID}" />
<KeyValuePair key="timestamp" value="${date:yyyy-MM-dd'T'HH:mm:ss.SSSZ}" />
</JSONLayout>
</Console>
</Appenders>
<Loggers>
<AsyncRoot level="info">
<AppenderRef ref="ConsoleJSONAppender" />
</AsyncRoot>
</Loggers>
</Configuration>
The configuration is properly loaded from config server because the logs are in json format, but "${date:yyyy-MM-dd'T'HH:mm:ss.SSSZ}" and "${ctx:CORRELATION_ID}" aren't resolved. Again I want to mention that if the configuration file is under resources folder this works. So this let me think that the problem is on the configuration file being on config server. There is any limitation on lookups if the file is on config server?
Thanks.
I assume you have reviewed the sample project at https://github.com/apache/logging-log4j2/tree/release-2.x/log4j-spring-cloud-config/log4j-spring-cloud-config-samples? It has both a sample client and a sample Spring Cloud Config service with a native repo. If you look at the sample log4j2.xml in the config-repo directory of the server you will notice that many of the lookup variables are escaped as \${ctx:CORRELATION_ID}
. Without this Spring cloud config will try to resolve the variable using the information it has, which won't be much. If present, the escape character will be removed by Spring Cloud Config as the configuration is passed back to Log4j.
As for monitorInterval, when setting it for SpringCloudConfig if it is a positive value Log4j will make a GET call to the url at each interval. If it receives a Not Modified response nothing happens. If it receives the configuration it will reconfigure. If the monitorInterval is 0 then Log4j will listen for an event from Spring Cloud Bus indicating that a change has occurred at which time it is request the configuration. Again, if a Not Modified is returned then something else triggered the event and the configuration will be left alone.
For the Spring Cloud Bus notification to work Spring Cloud Config needs to be configured to push events to applications and applications need to be configured to listen for them using the same type of message broker the server used. Finally, the Spring Cloud Config server needs a web hook configured to listen for events from your backing repository, assuming you are using Git. See https://cloud.spring.io/spring-cloud-config/multi/multi__push_notifications_and_spring_cloud_bus.html for a bit more information on that.