spring-cloud-config icon indicating copy to clipboard operation
spring-cloud-config copied to clipboard

Spring boot lookup not working in log4j2.xml while enabling logging through spring-cloud-starter-log4j2

Open aditi9991 opened this issue 3 years ago • 3 comments

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.

aditi9991 avatar Sep 15 '22 13:09 aditi9991

Are you using spring.config.import to specify the config server as a configuration source?

ryanjbaxter avatar Sep 15 '22 23:09 ryanjbaxter

Yes,I am using the spring.config.import property eqaul to 'optional:configserver:http://localhost:8888/config'

aditi9991 avatar Sep 16 '22 01:09 aditi9991

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

ryanjbaxter avatar Sep 16 '22 14:09 ryanjbaxter

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.

spring-cloud-issues avatar Sep 23 '22 14:09 spring-cloud-issues

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.

spring-cloud-issues avatar Sep 30 '22 14:09 spring-cloud-issues