繁体   English   中英

log4j:WARN找不到记录器的附加程序log4j:WARN请正确初始化log4j系统

[英]log4j:WARN No appenders could be found for logger log4j:WARN Please initialize the log4j system properly

任何人都可以帮我这个忙吗?

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

使用逗号而不是句点:

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

同样应该是模式而不是模式:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM