Home Ask Login Register

Developers Planet

Your answer is one click away!

ViChU February 2016

Using log4j2 in Servlet 3.0 application

I am trying to use Log4j2 in my Servlet 3.0 web application. Even after configuring everything as per the official documentation, I am not able to see the logs.

This is my web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"





I have placed the log4j2.xml file in WEB-INF/classes:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="INFO">
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
        <File name="MyFile" fileName="myapplication.log" immediateFlush="true" append="false">
            <PatternLayout pattern="%d{yyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
        <Root level="info">
            <AppenderRef ref="Console" />
            <AppenderRef ref        


Berger February 2016

With Servlet 3.0 , set isLog4jAutoInitializationDisabled to false, or remove it, and it should work .

If you keep it to true, you will have additional steps and things to add toweb.xml:

Once you disable auto-initialization, you must initialize Log4j as you would a Servlet 2.5 web application.


If you are using Log4j in a Servlet 2.5 web application, or if you have disabled auto-initialization with the isLog4jAutoInitializationDisabled context parameter, you must configure the Log4jServletContextListener and Log4jServletFilter in the deployment descriptor or programmatically.

See here Log4j2 and Servlet 3.0

Post Status

Asked in February 2016
Viewed 3,547 times
Voted 14
Answered 1 times


Leave an answer

Quote of the day: live life