log4j ContentAppender null when static

When ConsoleAppender is static, I get the following error from log4j: log4j:ERROR Attempted to append to closed appender named [null]. Example code: import org.apache.log4j.ConsoleAppender; import org.apache.log4j.Logger; import org.apache.log4j.PatternLayout; public class Logging { private static final PatternLayout layout = new PatternLayout("[%d{dd MMM yyyy HH:mm:ss}] [%t] %-6r %-5p %m\n"); private static final ConsoleAppender consoleAppender = new ConsoleAppender(layout); private Logger logger; private String filterClass; private boolean logFlag = false; public LoggingExample(Class c) { logger = Logger.getLogger(c); logger.setAdditivity(false); logger.removeAllAppenders(); logger.addAppender(consoleAppender); consoleAppender.activateOptions(); filterClass = c.getName(); } public log() { logger.info("this doesn't work when ConsoleAppender is static!"); } }

以上就是log4j ContentAppender null when static的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准