配置 log4j 的步骤是: 步骤 1. 创建文件:jboss-deployment-structure.xml
<jboss-deployment-structure>
<deployment>
<exclusions>
<module name="org.apache.log4j" slot="main"/>
<module name="org.apache.commons.logging"/>
</exclusions>
</deployment>
</jboss-deployment-structure>
步骤 2. 创建 servlet:Log4jInitServlet.java
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.Log;
public class Log4JInitServlet extends HttpServlet{
/**
*
*/
private static final long serialVersionUID = -3677208571865966932L;
private static final Log log=LogFactory.getLog(Log4JInitServlet.class);
public Log4JInitServlet(){
}
protected void doGet(HttpServletRequest request
,HttpServletResponse response) throws ServletException,IOException{
PrintWriter out = response.getWriter();
out.write("<h1>LogTester Application Version Guide Erasmo Marciano 1.0</h1>");
out.write("<p>Loading this page generates multiple log events for the it.deinformatica.marciano.logtest category.</p>");
out.write("<p>Click on F5 reload this web-page.</p>");
out.write("<p>You wii find level log:debug|fatal|error|trace|info|warn</p>");
out.close();
for (int i = 1; i <= 20; i++) {
log.debug("This is DEBUG message. Event number " + i);
log.fatal("This is FATAL message. Event number " + i);
log.info("This is INFO message. Event number " + i);
log.error("This is ERROR message. Event number " + i);
log.trace("This is TRACE message. Event number " + i);
log.warn("This is WARN message. Event number " + i);
}
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
步骤 3. 创建文件 log4j.properties
### set log levels - for more verbose logging change 'info' to 'debug' ###
log4j.rootLogger=info, stdout
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
发生的情况是只显示 INFO 消息而没有 DEBUG。我在做什么错或应该做什么来显示带有 lo4j DEBUG 的消息?请如果有人有类似的问题并解决它。