java - Using log4j2 in Servlet 3.0 application -


i trying use log4j2 in servlet 3.0 web application. after configuring per official documentation, not able see logs.

this 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"     xsi:schemalocation="http://java.sun.com/xml/ns/javaee            http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"     version="3.0">      <display-name>myapplication</display-name>      <context-param>         <param-name>islog4jautoinitializationdisabled</param-name>         <param-value>true</param-value>     </context-param>     <context-param>         <param-name>islog4jcontextselectornamed</param-name>         <param-value>true</param-value>     </context-param>      <context-param>         <param-name>log4jconfiguration</param-name>         <param-value>log4j2.xml</param-value>     </context-param>      <welcome-file-list>         <welcome-file>index.html</welcome-file>     </welcome-file-list> </web-app> 

i have placed log4j2.xml file in web-inf/classes:

<?xml version="1.0" encoding="utf-8"?> <configuration status="info">     <appenders>         <console name="console" target="system_out">             <patternlayout pattern="%d{hh:mm:ss.sss} [%t] %-5level %logger{36} - %msg%n" />         </console>         <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"/>         </file>     </appenders>     <loggers>         <root level="info">             <appenderref ref="console" />             <appenderref ref="myfile"/>         </root>     </loggers> </configuration> 

this how calling logger in class:

final static logger logger = logger.getlogger(myclass.class); logger.info("logging works"); 

please tell me doing wrong. have tried hardcoding direct path log4j2.xml, still not work.

with servlet 3.0 , set islog4jautoinitializationdisabled false, or remove it, , should work .

if keep true, have additional steps , things add toweb.xml:

once disable auto-initialization, must initialize log4j servlet 2.5 web application.

and

if using log4j in servlet 2.5 web application, or if have disabled auto-initialization islog4jautoinitializationdisabled context parameter, must configure log4jservletcontextlistener , log4jservletfilter in deployment descriptor or programmatically.

see here log4j2 , servlet 3.0


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -