如何禁用PDFBox警告日志记录

编程入门 行业动态 更新时间:2024-10-08 06:24:16
本文介绍了如何禁用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( commons. apache/logging/).有几种禁用Commons Logging的方法:

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

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

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

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

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

    -Dorg.apachemons.logging.Log=org.apachemons.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警告日志记录

    本文发布于:2023-11-25 21:29:06,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1631417.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:日志   PDFBox

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!