简体   繁体   English

轻松禁用applet的log4j吗?

[英]Easily disable log4j for applet?

I am building Java Desktop and Java Applet from the same code. 我正在用相同的代码构建Java Desktop和Java Applet。 Log4j is in use so almost every class in desktop version (which is original) has line like 使用Log4j,因此几乎所有台式机版本(原始版本)的行都类似

private static final Logger LOG = LoggerFactory.getLogger(EachClassName.class);

Because Applet is not supposed to perform any io operations I had to exclude this configuration code: 因为Applet不应该执行任何io操作,所以我不得不排除以下配置代码:

InputStream is = Log4jConfigurator.class.getClassLoader().getResourceAsStream(path);
properties.load(is);
is.close();
PropertyConfigurator.configure(properties);

But now I get warnings because getLogger is still in place 但是现在我收到警告,因为getLogger仍然存在

log4j:WARN No appenders could be found for logger (org.game.client.Client).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

What would be the most elegant solution to avoid this warnings and use logger only in desktop version? 避免这种警告并仅在台式机版本中使用记录器的最佳解决方案是什么?

In your "Applet App" try to configure log4j programmatically: 在“ Applet应用程序”中,尝试以编程方式配置log4j:

  1. turn off logging 关闭日志记录

    LogManager.getRootLogger().setLevel(Level.OFF);

  2. Add NullAppender (if setting Level.OFF is not enough) 添加NullAppender(如果设置Level.OFF不够)

    LogManager.getRootLogger().addAppender(new NullAppender())

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

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