我是log4j的新手。我看了很多教程。使用log4j。但没有一个对我有用。
我在jboss 7中使用log4j。
问题是文件已创建但未记录日志信息
这是我的属性文件
log4j.logger.org.hibernate=INFO
log4j.logger.org.hibernate.SQL=DEBUG
log4j.logger.org.hibernate.type=TRACE
log4j.logger.org.hibernate.hql.ast.AST=info
log4j.logger.org.hibernate.tool.hbm2ddl=warn
log4j.logger.org.hibernate.hql=debug
log4j.logger.org.hibernate.cache=info
log4j.logger.org.hibernate.jdbc=debug
log4j.rootLogger = DEBUG, FILE
log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.FILE.DatePattern='.'yyyy-MM-dd-a
log4j.appender.FILE.File=/home/latif/AutoGS.log
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout
log4j.appender.FILE.layout.conversionPattern= %d{HH:mm:ss} %-5p %c - %m%n
我的网络应用中的servlet是
package com.test;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
@WebServlet(name = "Helloworld", urlPatterns = {"/Helloworld"})
public class Helloworld extends HttpServlet {
final static Logger logger = Logger.getLogger(Helloworld.class.toString());
Logger APPLICATION_LOGS = Logger.getLogger("rootLogger");
/**
* Processes requests for both HTTP
* <code>GET</code> and
* <code>POST</code> methods.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PropertyConfigurator.configure("/home/latif/NetBeansProjects/FirstLog4jExample/src/java/log4j.properties");
try {
APPLICATION_LOGS.debug("Starting");
APPLICATION_LOGS.info("Starting");
logger.info("This is a logging statement from log4j");
String html = "<html><h2>Log4j has been initialized successfully!</h2></html>";
response.getWriter().println(html);
if (logger.isDebugEnabled()) {
logger.debug("###### This is debug : " + "Hmmm ");
}
if (logger.isInfoEnabled()) {
logger.info("******** This is info : " + "Hmmm ");
}
logger.warn("This is warn : " + "Hmmm ");
logger.error("This is error : " + "Hmmm ");
logger.fatal("This is fatal : " + "Hmmm ");
} finally {
}
}
// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
/**
* Handles the HTTP
* <code>GET</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Handles the HTTP
* <code>POST</code> method.
*
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
/**
* Returns a short description of the servlet.
*
* @return a String containing servlet description
*/
@Override
public String getServletInfo() {
return "Short description";
}// </editor-fold>
}
问题是文件已创建并且日志是在服务器控制台中打印的。但是日志信息没有写入文件中。
请提供任何建议。