简体   繁体   English

如何关闭MarkLogic Java API日志记录?

[英]How to turn off MarkLogic Java API logging?

I have trouble turning off MarkLogic log messages like these when uploading files to MarkLogic database through Java API: 通过Java API将文件上传到MarkLogic数据库时,无法关闭此类的MarkLogic日志消息:

16:24:01.599 [main] INFO  com.marklogic.client.io.DOMHandle - Serializing DOM document to output stream

I followed the information in MarkLogic Java API documentation about logging MarkLogic Java API documentation . 我遵循了MarkLogic Java API文档中有关记录MarkLogic Java API文档的信息 Here is how I initialize database client and xmlDocMgr: 这是我初始化数据库客户端和xmlDocMgr的方法:

databaseClient = DatabaseClientFactory.newClient(marklogicHost, marklogicPort, marklogicUser, password, Authentication.DIGEST);

ByteArrayOutputStream out = new ByteArrayOutputStream();
RequestLogger logger = databaseClient.newLogger(out);
logger.setEnabled(false);

xmlDocMgr = databaseClient.newXMLDocumentManager();
xmlDocMgr.stopLogging();

What am I doing wrong? 我究竟做错了什么? How to disable log messages? 如何禁用日志消息?

Thanks in advance! 提前致谢!

Based on the docs, I believe you need to call "xmlDocMgr.startLogging(logger)" first, which will register the RequestLogger with xmlDocMgr. 根据文档,我认为您首先需要调用“ xmlDocMgr.startLogging(logger)”,这将向xmlDocMgr注册RequestLogger。

The "stopLogging" call doesn't do anything based on what's in the docs: 根据文档中的内容,“ stopLogging”调用不会执行任何操作:

"If called on a manager not currently logging, nothing happens, not even an error or exception." “如果调用当前未登录的管理器,则不会发生任何事情,甚至不会发生错误或异常。”

The documentation section you referenced is unrelated--it's a different kind of logging you could use. 您引用的文档部分是无关的-您可以使用另一种日志记录。

What you're seeing is that MarkLogic Java API uses SLF4J for logging, and you should configure it with your perferred logging framework. 您看到的是MarkLogic Java API使用SLF4J进行日志记录,您应该使用您喜欢的日志记录框架对其进行配置。 In the current release (3.0.6) we include logback which automatically enables the logging you're seeing. 在当前版本(3.0.6)中,我们包括了logback,它会自动启用您正在查看的日志记录。 We removed logback from future releases since it's not really required, and the SLF4J philosophy is to allow you to choose your preferred logging framework. 由于不是真正需要日志记录,因此我们从将来的版本中删除了日志记录,SLF4J的理念是允许您选择首选的日志记录框架。

In any case, assuming you'd like to keep logback. 无论如何,假设您想保留登录。 Add a file named "logback.xml" to your classpath with the level set to "WARN" as in the following suggested contents: 将一个名为“ logback.xml”的文件添加到您的类路径中,级别设置为“ WARN”,如以下建议内容所示:

<configuration>
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
  </appender>

  <root level="WARN">
    <appender-ref ref="STDOUT" />
  </root>
</configuration>

I commented out the following section in POM to disable the log output. 我在POM中注释了以下部分以禁用日志输出。

<!--        <dependency>
        <groupId>com.marklogic</groupId>
        <artifactId>java-client-api</artifactId>
        <version>3.0.6</version>
    </dependency>-->

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

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