当前位置: 首页 > 知识库问答 >
问题:

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

甄成弘
2023-03-14

有人能帮我摆脱困境吗我收到了这个警告信息

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个答案

彭胡媚
2023-03-14

使用逗号而不是句点:

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

也应该是模式而不是模式:

log4j.appender.jlc.layout = org.apache.log4j.PatternLayout
                                                   ^ forgot this 'n' as well
 类似资料:
  • 我们编写了这样一个简单的类: [...] 启动服务器(WildFly 10.1.0)时,出现以下错误: 15:35:27142错误[stderr](ServerService线程池--58)log4j:警告找不到记录器(com.test.ContactFormScheduler)的附加程序。 15:35:27,143错误[stderr](ServerService线程池--58)log4j:警告请

  • 有人能帮我弄清楚为什么Jenkins在IDE上工作时一直抱怨log4j?我很熟悉这个错误和它的修复方法。我的src文件夹中有一个log4j.properties文件。当我从IDE运行测试时,我看不到这个错误。只从詹金斯那里。如有任何帮助,我们将不胜感激。 这不是同一个问题与我的链接!请看问题!这发生在JENKINS,而不是IDE中。

  • 我正在努力学习硒。 我收到以下错误消息: log4j:WARN找不到记录器(org.apache.http.client.protocol.RequestAddCookies)的追加器。log4j:警告请正确初始化log4j系统。log4j:请参阅http://logging.apache.org/log4j/1.2/faq.html#noconfig更多信息。 因此,我下载了文件,我在谷歌上搜索

  • 我尝试使用第二个日志文件与我的默认日志文件在servlet我有这个log4j.xml配置。 现在在servlet中,我将记录器设置为: 但在运行时:错误日志。调试(“启动应用程序”);我得到: log4j和log4j.xml在类路径我做错了什么?

  • 我已经将log4j放入了buildpath中,但在运行应用程序时会收到以下消息: 这些警告意味着什么?这里的附加符是什么?

  • 问题内容: 这是错误消息- 这是该类中的调用- 这是我的log4j.properties文件的内容- 属性文件在类路径上。 一切对我来说都很好,这是怎么回事?如果不是门槛也可拍摄记录? 问题答案: 好了,所以我通过更改 对此 显然,您必须将日志记录级别指定为第一个?如果我浪费任何人的时间,我深表歉意。 另外,我决定回答我自己的问题,因为这不是类路径问题。