简体   繁体   English

静音斯坦福 coreNLP 日志记录

[英]Mute Stanford coreNLP logging

First of all, Java is not my usual language, so I'm quite basic at it.首先,Java 不是我常用的语言,所以我很基础。 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:我已经能够实现 coreNLP,并且似乎可以正常工作,但是会生成很多消息,例如:

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.经过一些研究(文档、谷歌、这里的其他线程),我认为(抱歉,我不知道我如何确定)coreNLP 正在我的类路径中找到slf4j-api.jar ,并通过它登录。

Which properties of the JVM can I use to set logging level of the messages that will be printed out?我可以使用 JVM 的哪些属性来设置将要打印的消息的日志记录级别?

Also, in which .properties file I could set them?另外,我可以在哪个.properties文件中设置它们? (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). (我的项目资源文件夹中已经有一个commons-logging.properties 、一个simplelog.properties和一个StanfordCoreNLP.properties来设置其他包的属性)。

Om's answer is good, but two other possibly useful approaches: Om 的回答很好,但还有另外两种可能有用的方法:

  • 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");如果只是来自分词器的这些警告让您烦恼,您可以(在代码中或在 StanfordCoreNLP.properties 中)设置一个属性使它们消失: props.setProperty("tokenize.options", "untokenizable=NoneKeep"); . .
  • If slf4j is on the classpath, then, by default, our own Redwoods logger will indeed log through slf4j.如果 slf4j 在类路径上,那么默认情况下,我们自己的 Redwoods 记录器确实会通过 slf4j 进行日志记录。 So, you can also set the logging level using slf4j.因此,您还可以使用 slf4j 设置日志记录级别。

If I understand your problem, you want to disable all StanfordNLP logging message while the program is executing.如果我理解你的问题,你想在程序执行时禁用所有 StanfordNLP 日志消息。

You can disable the logging message.您可以禁用日志消息。 Redwood logging framework is used as logging framework in Stanford NLP. Redwood日志框架在斯坦福 NLP 中用作日志框架。 First, clear the Redwood 's default configuration(to display log message) then create StanfordNLP pipeline.首先,清除Redwood的默认配置(以显示日志消息),然后创建 StanfordNLP 管道。

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按照克里斯托弗曼宁的建议,我按照这个链接如何配置slf4j-simple

I created a file src/simplelogger.properties with the line org.slf4j.simpleLogger.defaultLogLevel=warn .我用org.slf4j.simpleLogger.defaultLogLevel=warn行创建了一个文件src/simplelogger.properties

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
    }

}

Om's answer disables all logging. Om 的回答禁用了所有日志记录。 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:我还使用 jdk 日志记录而不是 slf4j 日志记录来避免加载 slfj 依赖项,如下所示:

RedwoodConfiguration.javaUtilLogging().apply();

Both options can be used together and in any order.这两个选项可以以任何顺序一起使用。 Required import is:所需的导入是:

import edu.stanford.nlp.util.logging.RedwoodConfiguration;

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

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