13

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.

I am using Tomcat 5.5, log4j 1.2.16 and pdfbox-app 1.6.0

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

EDIT

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

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

EDIT 2

After consulting log4j: package-specific logging I discovered the right syntax:

log4j.logger.org.apache.pdfbox=ERROR
Community
  • 1
  • 1
Janis Peisenieks
  • 4,938
  • 10
  • 55
  • 85
  • 1
    See http://stackoverflow.com/questions/728295/creating-multiple-log-files-of-different-content-with-log4j – Kennet Jul 13 '12 at 08:21
  • possible duplicate of [Adjust Logging level for apache commons logging?](http://stackoverflow.com/questions/5009658/adjust-logging-level-for-apache-commons-logging) – Wolfgang Fahl Jul 06 '15 at 13:43
  • the logging is not only annoying its a major performance killer ... – Wolfgang Fahl Jul 06 '15 at 13:46

3 Answers3

16

Simple way to disable all logging:

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

Or if you want to only see the severe messages:

java.util.logging.Logger
    .getLogger("org.apache.pdfbox").setLevel(java.util.logging.Level.SEVERE);
Philipp Ludwig
  • 3,758
  • 3
  • 30
  • 48
  • 1
    I'd suggest you change the "OFF" to something less extreme, copy & paste newbies would not see the messages and then open "it doesn't work" issues. See also http://hitchhikers.wikia.com/wiki/Ravenous_Bugblatter_Beast_of_Traal – Tilman Hausherr Mar 17 '17 at 10:21
  • @TilmanHausherr Next time you see a mistake like this you might consider just fixing it yourself. The edit button is there for a reason. – wvdz Oct 31 '17 at 11:12
  • @wvdz I know, but when something is a matter of opinion, I avoid pushing this on users. – Tilman Hausherr Oct 31 '17 at 11:21
  • @wvdz The question however was how the logging of PDFBox could be disabled, not reduced. I incorporated your edit as a suggestion, but I personally don't think that this is helpful in this case, as PDFBox spits all kinds of crap in the SEVERE log level. – Philipp Ludwig Nov 15 '17 at 20:14
  • 1
    When running unit tests with fuzzing with something like QuickTheories you really want to set it to `Level.SEVERE` or `Level.OFF` – Hans Mar 23 '18 at 14:25
  • Did not work for me. I'm using log4j2 in my app, not sure if it's related. – Nicolas Jul 19 '20 at 01:05
  • @TilmanHausherr Three years later I still don’t get the hitchhiker reference you made. – Philipp Ludwig Sep 03 '20 at 09:41
  • 1
    "One of the main features of the Beast is that if you can't see it, it assumes it can't see you." Switching logging off is like using the glasses that Zaphod Beeblebrox uses in the 80ies series, which go dark when there's a danger. – Tilman Hausherr Sep 03 '20 at 11:34
6

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
Mark Bakker
  • 1,278
  • 8
  • 19
  • I take the accepted answer back. This doesn't seem to work. The errors still get logged. – Janis Peisenieks Jul 13 '12 at 10:07
  • if you put 'org.apache.pdfbox.pdmodel.font' to error/fatal it should be gone. There are several classes in this package which give unwanted logging like org.apache.pdfbox.pdmodel.font.PDFont but also org.apache.pdfbox.pdmodel.font.PDSimpleFont – Mark Bakker Jul 13 '12 at 10:44
  • But where do I put this mysterious log4j.properties file? Can't find any valid information about it. – Philipp Ludwig Mar 17 '17 at 09:14
  • 1
    @PhilippLudwig this depends on whether it is maven or not. Better ask a new question, although this is likely a duplicate of an existing one. With netbeans and non-maven, just put it in the default package. With maven, put it in "Other sources", src/main/resources, default package. – Tilman Hausherr Mar 17 '17 at 10:08
  • @TilmanHausherr thanks for your response. Turned out I had the properties file in the resources folder of the wrong project, *doh*. Anyway, I've figured out a simple way for this problem and posted it as an answer. – Philipp Ludwig Mar 17 '17 at 10:14
3

This works for me: - please note that there are multiple questions like this were this answer applies and I was already asked to mark things as duplicate. So if someone finds the time for this - just go ahead and merge ...

 // you might want to switch off logging here to improve performance
        String[] loggers = { "org.apache.pdfbox.util.PDFStreamEngine",
            "org.apache.pdfbox.pdmodel.font.PDSimpleFont",
            "org.apache.pdfbox.pdmodel.font.PDFont",
            "org.apache.pdfbox.pdmodel.font.FontManager",
            "org.apache.pdfbox.pdfparser.PDFObjectStreamParser" };
        for (String logger : loggers) {
          org.apache.log4j.Logger logpdfengine = org.apache.log4j.Logger
              .getLogger(logger);
          logpdfengine.setLevel(org.apache.log4j.Level.OFF);
        }
Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186
  • 1
    This works great for me too. For whatever reason, I had to add one more to my list: `org.apache.pdfbox.pdmodel.graphics.xobject.PDPixelMap` – Jonathan Mar 25 '16 at 12:06