我们正在使用 PDFBox 进行一些 PDF 阅读和操作。但是在解析过程中,我收到了一堆这样的消息:
Changing font on <m> from <Arial Bold> to the default font
现在我该如何禁用这些?因为如果嵌入了字体,那么在输入的每个字符上都会输出这样的消息,因此日志文件变得非常不可用。
现在更改整体日志级别不是一种选择,因为我需要来自其他组件的语句。
我正在使用 Tomcat 5.5、log4j 1.2.16 和 pdfbox-app 1.6.0
这是我的 log4j 配置文件:
# 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 文件后,它是这样的:
# 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
条线放在哪里,错误仍然会在日志文件中不断弹出:
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: package-specific logging之后,我发现了正确的语法:
log4j.logger.org.apache.pdfbox=ERROR