Mute Stanford coreNLP logging
Asked Answered
W

5

2

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 relevant information, please ask for it, I will be happy to provide it.

I have been able to implement coreNLP, and, seemingly, have it working right, but is generating lots of messages like:

ene 20, 2017 10:38:42 AM edu.stanford.nlp.process.PTBLexer next
ADVERTENCIA: Untokenizable: 【 (U+3010, decimal: 12304)

After some research (documentation, google, other threads here), I think (sorry, I don't know how I can tell for sure) coreNLP is finding the slf4j-api.jar in my classpath, and logging through it.

Which properties of the JVM can I use to set logging level of the messages that will be printed out?

Also, in which .properties file I could set them? (I already have a commons-logging.properties, a simplelog.properties and a StanfordCoreNLP.properties in my project's resource folder to set properties for other packages).

Warfold answered 20/1, 2017 at 10:15 Comment(0)
B
3

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.
Buddhism answered 26/10, 2017 at 21:47 Comment(0)
N
1

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.

Northwester answered 26/10, 2017 at 16:59 Comment(0)
T
0

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.

Troglodyte answered 29/12, 2017 at 2:46 Comment(0)
G
0

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
    }

}
Godlike answered 12/2, 2018 at 10:13 Comment(0)
T
0

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;
Tetrabranchiate answered 12/6, 2020 at 11:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.