Log4j Init error : Unable to create Lookup for bundle java.lang.ClassCastException: class org.apache.logging.log4j.core.lookup.ResourceBundleLookup

I am trying to initialize log4j2 in my servlet application (apache-tomcat 9). I am getting a series of exceptions

2024-09-26T07:58:02.478967Z main ERROR Unable to create Lookup for bundle java.lang.ClassCastException: class org.apache.logging.log4j.core.lookup.ResourceBundleLookup
        at java.base/java.lang.Class.asSubclass(Class.java:3924)
2024-09-26T07:58:02.480089Z main ERROR Unable to create Lookup for ctx java.lang.ClassCastException: class org.apache.logging.log4j.core.lookup.ContextMapLookup
        at java.base/java.lang.Class.asSubclass(Class.java:3924)

With series of

2024-09-26T07:58:07.538777Z main ERROR Unrecognized format specifier [msg]
2024-09-26T07:58:07.538808Z main ERROR Unrecognized conversion specifier [msg] starting at position 54 in conversion pattern.
2024-09-26T07:58:07.538844Z main ERROR Unrecognized format specifier [n]
2024-09-26T07:58:07.538875Z main ERROR Unrecognized conversion specifier [n] starting at position 56 in conversion pattern.

In my code I have the log4j2.properties in this folder

src/main/webapp/WEB-INF/

This is my log4j2.properties content

# Set root logger level to DEBUG and its only appender to Console
log4j.rootLogger=DEBUG, Console

# Console appender configuration
log4j.appender.Console.type=Console
log4j.appender.Console.name=STDOUT
log4j.appender.Console.layout.type=PatternLayout
log4j.appender.Console.layout.pattern=%d{yyyy-MM-dd HH:mm:ss} [%t] %-5p %c{1} - %m%n



# Define appenders
appender.console.type = Console
appender.console.name = CONSOLE
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %highlight{%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n}{FATAL=red, ERROR=red, WARN=yellow, INFO=green, DEBUG=blue}

appender.file.type = File
appender.file.name = FILE
appender.file.fileName = logs/application.log
appender.file.layout.type = PatternLayout
appender.file.layout.pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n

# Define loggers
rootLogger.level = INFO
rootLogger.appenderRef.console.ref = CONSOLE
rootLogger.appenderRef.file.ref = FILE

logger.my.package.first.name = my.package.first
logger.my.package.first.level = DEBUG
logger.my.package.first.appenderRef.file.ref = FILE

logger.my.package.second.name = my.package.second
logger.my.package.second.level = DEBUG
logger.my.package.second.appenderRef.file.ref = FILE

My src/main/webapp/WEB-INF/web.xml has the following content

<listener>
        <listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class>
    </listener>

    <context-param>
        <param-name>log4jConfiguration</param-name>
        <param-value>log4j2.properties</param-value>
    </context-param>

    <context-param>
        <param-name>log4j2.debug</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>log4j2.verbose</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>log4j.shutdownHookEnabled</param-name>
        <param-value>true</param-value>
    </context-param>

I have downloaded the following files and copied it to the tomcat/lib folder

  • log4j-web-2.24.0
  • log4j-core-2.24.0
  • log4j-api-2.24.0
  • log4j-jul-2.24.0

I have referred to many links on SO

  • One link hinted that unable to find log4j2.properties file, so I copied log4j2.properties to lib, conf, webapps, webapps/myapp, webapps/myapp/classes folders and checked, no luck same error
  • Other links hinted that content may in incorrect

What am I missing?

I wont be able to exclude the .dat file as per this link since the init is happening via web.xml

I found the root cause. I had this dependency causing the issue. Once I removed it, the problem went away.

<dependency>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-slf4j2-impl</artifactId>
  <version>2.24.0</version>
</dependency>

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