Ashok
Ashok

Reputation: 81

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

Can any one help me out of this I am getting this Warning message

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

The class:

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 file : I have specified like this

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

Upvotes: 1

Views: 3925

Answers (1)

Lodewijk Bogaards
Lodewijk Bogaards

Reputation: 19987

Use a comma instead of a period:

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

Also it should be Pattern not Patter:

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

Upvotes: 1

Related Questions