Spring-Boot 3.4 not loading log4j2.xml file

I am trying to leverage log4j2 within my spring-boot app. Long term the goal is to leverage some of the DB appenders that log4j2 supports, but initially just trying to make sure it’s loading log4j instead of logback.

I have my log4j2.xml file located in my src/main/resources folder.

Im using gradle for my build and have the following config

implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'com.fasterxml.jackson.core:jackson-databind'
    implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml'
    implementation 'org.postgresql:postgresql'
    implementation 'org.springframework.data:spring-data-mongodb:4.4.0'
    implementation 'org.springframework.data:spring-data-commons:3.4.0'
    implementation 'org.springframework.boot:spring-boot-starter-actuator:3.4.0'
    implementation 'org.mongodb:mongodb-driver-sync:5.2.1'
    implementation 'org.mongodb:mongodb-driver-core:5.2.1'
    implementation 'com.google.code.gson:gson:2.11.0'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation "me.paulschwarz:spring-dotenv:4.0.0"
    implementation 'org.apache.logging.log4j:log4j-mongodb:2.24.3'
    implementation "org.springframework.boot:spring-boot-starter-log4j2:3.4.0"
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testRuntimeOnly 'org.junit.platform:junit-platform-launcher'

    modules {
        module("org.springframework.boot:spring-boot-starter-logging") {
            replacedBy("org.springframework.boot:spring-boot-starter-log4j2", "Use Log4j2 instead of Logback")
        }
    }

The modules component at the bottom seems to be correctly replacing all instances of spring-boot-start-logging with spring-boot-starter-log4j2. I was able to verify that with the output of the ./gradlew dependencies which produced this output for every line that had spring-boot-starter-logging.

|    |    |    +--- org.springframework.boot:spring-boot-starter-logging:3.3.5 -> org.springframework.boot:spring-boot-starter-log4j2:3.4.0
|    |    |    |    +--- org.apache.logging.log4j:log4j-slf4j2-impl:2.24.1 -> 2.23.1
|    |    |    |    |    +--- org.apache.logging.log4j:log4j-api:2.23.1
|    |    |    |    |    +--- org.slf4j:slf4j-api:2.0.9 -> 2.0.16
|    |    |    |    |    --- org.apache.logging.log4j:log4j-core:2.23.1
|    |    |    |    |         --- org.apache.logging.log4j:log4j-api:2.23.1
|    |    |    |    +--- org.apache.logging.log4j:log4j-core:2.24.1 -> 2.23.1 (*)
|    |    |    |    --- org.apache.logging.log4j:log4j-jul:2.24.1 -> 2.23.1
|    |    |    |         --- org.apache.logging.log4j:log4j-api:2.23.1

I also verified that I don’t have any instances of slf4j implementations other than the one shown above from log4j2.

When I run the app, the log4j2.xml file is completely ignored. I know this because it references an invalid path for where to put the FileAppender output that shoudl throw an error (this was done on purpose to make testing easier).

If I try to force the loading of the file by setting

logging:
   config: classpath:log4j2.xml

in my application.yml file, I just get a new block at the top of my console on execution complaining about logback-classic and then I get the SPRING ANSI art and that’s it. No other calls to the Log4j impl actually come through and no files are ever created.

I feel like there has to be something simple I am missing as all of the articles I can find seem to imply that I have done all of the correct things to make this work, but I sure can’t find the issue.

I am expecting to get an error because log4j2.xml is attempting to write to a log file located at c:/temp which is an invalid path on my Mac.

I also attempted to try using the log4j2.yml file to see if that was working, and what I get when I do that via the

logger:
   config: classpath:log4j2.yml

entry is an error message stating that only XML formats are valid here.

New contributor

Josh Smith is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật