禁用PDFBox上的日志记录 [英] Disabling logging on PDFBox
问题描述
我们正在使用PDFBox进行一些PDF阅读和操作。但是在解析过程中,我得到了一堆像这样的消息:
We are using PDFBox to do some PDF reading and manipulations. But during the parsing, I get a bunch of messages like this one:
Changing font on <m> from <Arial Bold> to the default font
现在如何禁用这些?因为如果嵌入了字体并且日志文件变得非常不可用,则输入的每个字符都会输出这样的消息。
Now how can I disable these? Because a message like this is output on EVERY character of the input if the font is embedded and the log files therefore become pretty unusable.
现在更改整体日志级别不是一个选项,因为我需要来自其他组件的语句。
Now changing the overall log level is not an option, because I need the statements from other components.
我使用的是Tomcat 5.5,log4j 1.2.16和pdfbox-app 1.6.0
I am using Tomcat 5.5, log4j 1.2.16 and pdfbox-app 1.6.0
这里是我的log4j配置文件:
And here is my log4j config file:
# Root logger option
log4j.rootLogger=INFO, file, stdout
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
#log4j.appender.file.File=/home/PDF/WS/PDF.log
log4j.appender.file.File=C:\\loging.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ISO8601} %-5p [%c{2}]: %m%n
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ISO8601} %-5p [%c{2}]: %m%n
编辑
修改我的log4j文件后,它的外观如下:
After modifying my log4j file, this is how it looks:
# Root logger option
log4j.rootLogger=INFO, file, stdout
log4j.rootLogger.org.apache.pdfbox=ERROR
# Direct log messages to a log file
log4j.appender.file=org.apache.log4j.DailyRollingFileAppender
#log4j.appender.file.File=/home/PDF/WS/PDF.log
log4j.appender.file.File=C:\\loging.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=1
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ISO8601} %-5p [%c{2}]: %m%n
# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ISO8601} %-5p [%c{2}]: %m%n
无论我把 log4j.rootLogger.org.apache.pdfbox = ERROR
行放在哪里,错误仍然会在日志文件中弹出如下:
No matter where I put the log4j.rootLogger.org.apache.pdfbox=ERROR
line, errors still keep popping up like this in the log files:
2012-07-16 15:36:46,652 WARN [font.PDSimpleFont]: Changing font on <r> from <Arial Bold> to the default font
2012-07-16 15:36:46,652 WARN [font.PDSimpleFont]: Changing font on <o> from <Arial Bold> to the default font
2012-07-16 15:36:46,667 WARN [font.PDSimpleFont]: Changing font on <c> from <Arial Bold> to the default font
2012-07-16 15:36:46,667 WARN [font.PDSimpleFont]: Changing font on <e> from <Arial Bold> to the default font
2012-07-16 15:36:46,667 WARN [font.PDSimpleFont]: Changing font on <s> from <Arial Bold> to the default font
2012-07-16 15:36:46,667 WARN [font.PDSimpleFont]: Changing font on <u> from <Arial Bold> to the default font
2012-07-16 15:36:46,667 WARN [font.PDSimpleFont]: Changing font on < > from <Arial Bold> to the default font
2012-07-16 15:36:46,667 WARN [font.PDSimpleFont]: Changing font on <P> from <Arial Bold> to the default font
编辑2
在咨询 log4j:特定于软件包的日志记录后,我发现了正确的语法:
After consulting log4j: package-specific logging I discovered the right syntax:
log4j.logger.org.apache.pdfbox=ERROR
推荐答案
如果您将以下行添加到log4j.properties它应该清理,pdfbox会像您之前所说的那样记录错误东西
pdfbox does alot logging on error like you stated before, if you add the following line to the log4j.properties it should clean thing up
log4j.rootLogger.org.apache.pdfbox.pdmodel.font.PDFont=fatal
这篇关于禁用PDFBox上的日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!