log4j:WARN没有找到logger log4j的appender:WARN请正确初始化log4j系统

时间:2013-03-11 15:19:54

标签: java log4j

任何人都可以帮助我摆脱这个警告信息

log4j:WARN No appenders could be found for logger (com.akak.book.shop.listener.LogContextListener).
log4j:WARN Please initialize the log4j system properly.

班级:

public class LogContextListener implements ServletContextListener{

  @Override
  public void contextDestroyed(ServletContextEvent ctxEvent) {
  }

  @Override
  public void contextInitialized(ServletContextEvent ctxEvent) {
    ServletContext ctx = ctxEvent.getServletContext();
    String path = ctx.getRealPath("/") + "logs\\";
    System.setProperty("jlcindia.root.path", path);
    String str = ctx.getRealPath("/WEB-INF/classes/com/jlc/jlc-log4j.properties");
    PropertyConfigurator.configure(str);
    Logger log = Logger.getLogger(this.getClass());
    log.info("Properties file:"+ str);
  }
}

jlc-log4j.properties文件:我已经指定了这个

log4j.rootLogger = ERROR.jlc
log4j.appender.jlc = org.apache.log4j.FileAppender
log4j.appender.jlc.file = ${jlcindia.root.path}/jlcindia.log
log4j.appender.jlc.layout = org.apache.log4j.PatterLayout
log4j.appender.jlc.layout.ConversionPattern = %p %l %m %n

1 个答案:

答案 0 :(得分:1)

使用逗号代替句点:

log4j.rootLogger = ERROR,jlc
                        ^ comma, not period

它也应该是Pattern not Patter:

log4j.appender.jlc.layout = org.apache.log4j.PatternLayout
                                                   ^ forgot this 'n' as well