Spring boot lookup not working in log4j2.xml while enabling logging through spring-cloud-starter-log4j2
Below version are used <spring.framework.version>5.3.21</spring.framework.version> <spring.boot.version>2.7.1</spring.boot.version> <spring-cloud.version>2021.0.3</spring-cloud.version>
I am trying to implement logging in spring boot using the log4j2 library. I am facing issue in getting my spring environment properties resolved/interpolated inside my log4j2.xml , This is happening when the log4j2.xml is placed in the configuration gitlab repo and is accessed through spring-cloud-config-server. The log4j2.xml has below contents
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern= "${spring:spring.application.name} - ${spring:runtime-env} %d{yyyy-MM-dd HH:mm:ss} log4j2-dev %5p %c{1}:%L - %m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</configuration>
Here , ${spring:spring.application.name} and ${spring:runtime-env} are defined inside application.yaml in the remote configuration repo. the dependencies used for log4j2 library are below:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
<version>2.7.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-spring-cloud-config-client</artifactId>
<version>2.18.0</version>
</dependency>
And i mention the logging.config property as 'http://localhost:8888/config/application/default/main/log4j2.xml' where localhost:8888/config is the config server running on the system
Note: When I put the log4j2.xml inside the src/main/resources and replace the logging.config property eqaul to classpath:log4j2.xml' , the properties ${spring:spring.application.name} and ${spring:runtime-env} , get resolved to watever defined inside the application.yaml . Please let me know if any other information is also needed.
Are you using spring.config.import to specify the config server as a configuration source?
Yes,I am using the spring.config.import property eqaul to 'optional:configserver:http://localhost:8888/config'
Could you try using bootstrap instead and see if it makes a difference? https://docs.spring.io/spring-cloud-config/docs/current/reference/html/#config-first-bootstrap
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.