Mute Stanford coreNLP logging

蹲街弑〆低调 提交于 2019-12-02 01:26:39

Om’s answer is good, but two other possibly useful approaches:

  • If it is just these warnings from the tokenizer that are annoying you, you can (in code or in StanfordCoreNLP.properties) set a property so they disappear: props.setProperty("tokenize.options", "untokenizable=NoneKeep");.
  • If slf4j is on the classpath, then, by default, our own Redwoods logger will indeed log through slf4j. So, you can also set the logging level using slf4j.

If I understand your problem, you want to disable all StanfordNLP logging message while the program is executing.

You can disable the logging message. Redwood logging framework is used as logging framework in Stanford NLP. First, clear the Redwood's default configuration(to display log message) then create StanfordNLP pipeline.

import edu.stanford.nlp.util.logging.RedwoodConfiguration;
RedwoodConfiguration.current().clear().apply();
StanfordCoreNLP pipeline = new StanfordCoreNLP(props);

Hope it helps.

In accordance with Christopher Manning's suggestion, I followed this link How to configure slf4j-simple

I created a file src/simplelogger.properties with the line org.slf4j.simpleLogger.defaultLogLevel=warn.

I am able to solve it by setting a blank output stream to system error stream.

System.setErr(new PrintStream(new BlankOutputStream())); // set blank error stream
// ... Add annotators ...
System.setErr(System.err); // Reset to default

Accompanying class is

public class BlankOutputStream extends OutputStream {

    @Override
    public void write(int b) throws IOException {
        // Do nothing
    }

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!