Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring 5 how to use Log4jConfigListener

In the past, i used to spring 4.3.8 version, i used to Log4j config in web.xml like below code,

<context-param>
        <param-name>log4jConfigLocation</param-name>
        <param-value>classpath:/log4j-${spring.profiles.active}.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
    </listener>

Currently, i trying to use spring 5.0.7 version but, i can't use Log4jConfigListener

i realized Log4jConfigListener is not exist in spring 5.x version

I can use "log4j.xml"(default name) but i want to use custom name for sever,local environment

how can i do?

like image 539
jeongwon heo Avatar asked Dec 20 '18 12:12

jeongwon heo


3 Answers

The Log4jConfigListener has been removed as of Spring 4.2.1, in favor of Apache Log4j 2.

See the relevant information Spring 4.2.1 deprecation list:

org.springframework.web.util.Log4jConfigListener

as of Spring 4.2.1, in favor of Apache Log4j 2 (following Apache's EOL declaration for log4j 1.x)

You can configure environments in the XML file using Environment Lookup.

like image 51
Nikolas Charalambidis Avatar answered Sep 20 '22 22:09

Nikolas Charalambidis


Just Remove the listener from web.xml and put log4j.properties file in your classpath. then you will get your result.

like image 45
avdhesh Avatar answered Sep 22 '22 22:09

avdhesh


org.springframework.web.util.Log4jConfigListener is deprecated as of Spring 4.2.1, in favor of Apache Log4j 2 (following Apache's EOL declaration for log4j 1.x)

as an alternate you can change your configuration to use org.apache.logging.log4j.web.Log4jServletContextListener (log4j-web) More details can be found here https://logging.apache.org/log4j/2.x/manual/webapp.html

like image 45
satish.kanikaram Avatar answered Sep 18 '22 22:09

satish.kanikaram