Log4j configuration not used

My log4j logger does not want to use the log4j.xml file for configuration. This file is located in the src folder and looks like this:

 <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> <log4j:configuration> <appender name="ROLLING" class="org.apache.log4j.RollingFileAppender"> <param name="File" value="C:\debug\myproject\logfile.log" /> <param name="MaxFileSize" value="10024KB" /> <param name="MaxBackupIndex" value="5" /> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%-5p %d{dd-MM HH:mm:ss,SSS} (%F:%M:%L) -%m%n" /> </layout> <filter class="org.apache.log4j.varia.LevelRangeFilter"> <param name="LevelMin" value="DEBUG" /> <param name="LevelMax" value="FATAL" /> </filter> </appender> <root> <level value="DEBUG" /> <appender-ref ref="ROLLING" /> </root> </log4j:configuration> 

But logfile.log is still empty and there is no "DEBUG" line in the console.

NB: this is a Java EE project on JBoss 7.1.0 and using Struts2.

+1
source share
3 answers

The following answer is not entirely mine. This was posted in the OP question itself, so I will go to this community wiki answer.


I enabled it by explicitly configuring the logging configuration.

Note that you cannot change the configuration at run time if you configure it using a file.

See https://docs.jboss.org/author/display/AS71/How+To#HowTo-HowdoIuselog4j.propertiesorlog4j.xmlinsteadofusingtheloggingsubsystemconfiguration%3F for more information

+1
source

Make sure the log4j.xml file is located in the /WEB-INF/classes your web application.

0
source

The problem was in the log file. If you use an absolute file name, be sure to replace the backslash with a slash. for instance

 <param name="File" value="C:/debug/myproject/logfile.log" /> 
0
source

Source: https://habr.com/ru/post/946061/


All Articles