Mute Stanford coreNLP logging

后端 未结 5 1776
深忆病人
深忆病人 2021-01-14 20:42

First of all, Java is not my usual language, so I\'m quite basic at it. I need to use it for this particular project, so please be patient, and if I have omitted any relevan

相关标签:
5条回答
  • 2021-01-14 21:17

    Om's answer disables all logging. However, if you wish to still log errors then use:

    RedwoodConfiguration.errorLevel().apply();
    

    I also use jdk logging instead of slf4j logging to avoid loading slfj dependencies as follows:

    RedwoodConfiguration.javaUtilLogging().apply();
    

    Both options can be used together and in any order. Required import is:

    import edu.stanford.nlp.util.logging.RedwoodConfiguration;
    
    0 讨论(0)
  • 2021-01-14 21:23

    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.

    0 讨论(0)
  • 2021-01-14 21:24

    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.

    0 讨论(0)
  • 2021-01-14 21:29

    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
        }
    
    }
    
    0 讨论(0)
  • 2021-01-14 21:32

    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.
    0 讨论(0)
提交回复
热议问题