如何禁用PDFBox警告日志记录 [英] How to disable PDFBox warn logging

查看:742
本文介绍了如何禁用PDFBox警告日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Java控制台应用程序. pdfbox用于从PDF文件提取文本.但是控制台中会打印出连续的信息:

I have a simple java console application. pdfbox is utilized to extract text from PDF files. But there is continuous info printed in console:

十一月 29, 2017 9:28:27 下午 org.apache.pdfbox.pdmodel.font.PDSimpleFont toUnicode
警告: No Unicode mapping for 14 (145) in font GGNHDZ+SimSun  
十一月 29, 2017 9:28:27 下午 org.apache.pdfbox.pdmodel.font.PDSimpleFont toUnicode
警告: No Unicode mapping for 28 (249) in font LNKLJH+SimSun
十一月 29, 2017 9:28:27 下午 org.apache.pdfbox.pdmodel.font.PDSimpleFont toUnicode

我真的很想从控制台中删除此信息.我使用logback进行记录,logback.xml就像:

I really want to remove this information from the console. And I use logback for logging, the logback.xml is just like:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<logger name="org.apache.pdfbox" level="ERROR"/>
<timestamp key="timestamp-by-second" datePattern="yyyyMMdd'T'HHmmss"/>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <!-- encoder 默认配置为PatternLayoutEncoder -->
    <encoder>
        <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
    <file>logs/test-${timestamp-by-second}.log</file>
    <append>true</append>
    <encoder>
        <pattern>%-4relative [%thread] %-5level %logger{35} - %msg%n
        </pattern>
    </encoder>
</appender>
<root level="ERROR">
    <appender-ref ref="FILE" />
    <appender-ref ref="STDOUT" />
</root>

我找到了一些答案,应该改变等级.我已将级别更改为错误.但仍然无法正常工作.我怀疑信息中是否包含logback.xml.因为当我删除STDOUT时,pdfbox警告信息仍会在控制台中打印.

I have find some answer say that should change the Level. I have changed the level to ERROR. But still not work. I am doubting if the info has something with logback.xml. Because when I remove STDOUT, the pdfbox warn info still print in the console.

有人知道这种情况吗?预先谢谢你.

Anybody know this case? Thank you in advance.

推荐答案

如果Logback发出了日志记录,那么您尝试过的方法,例如...

If the logging was being emitted by Logback then the approach you have tried, for example ...

  • 添加<logger name="org.apache.pdfbox" level="ERROR"/>
  • 删除STDOUT附加器
  • Adding <logger name="org.apache.pdfbox" level="ERROR"/>
  • Removing the STDOUT appender

...会工作.

但是,PDFBox不使用Logback,而是使用Apache Commons Logging( http://commons. apache.org/logging/).有几种禁用Commons Logging的方法:

However, PDFBox doesn't use Logback, instead it uses Apache Commons Logging (http://commons.apache.org/logging/). There are several ways of disabling Commons Logging:

  • 通过将以下内容添加到Main类的静态初始化程序块中来完全禁用Commons Logging,必须在PDFBOX创建Log实例之前执行此 :

static {
    System.setProperty("org.apache.commons.logging.Log",
                 "org.apache.commons.logging.impl.NoOpLog");
}

  • 通过在启动应用程序时传递以下JVM参数来禁用Commons Logging:

  • Disable Commons Logging by passing the following JVM parameter when you start your application:

    -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.NoOpLog` 
    

  • 通过将以下内容添加到Main类的静态初始化程序块中来禁用PDFBOX命名空间的公共日志记录,此*必须**在PDFBOX创建Log实例之前执行(注意:您可以选择使用,具体取决于您对PDFBOX日志输出的容忍程度):

  • Disable Commons Logging for the PDFBOX namespace by adding the following to your Main class' static initialiser block, this *must** be executed before PDFBOX creates a Log instance (note: you could alternatively use Level.SEVERE, depending on how much tolerance you have for PDFBOX's log output):

    java.util.logging.Logger.getLogger("org.apache.pdfbox")
        .setLevel(java.util.logging.Level.OFF);
    

  • 这篇关于如何禁用PDFBox警告日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆