Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-2566

Remove logging from operator classes

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.0.0
    • 2.0.0
    • PDModel
    • None

    Description

      I've been trying to get better control over the logging that occurs in the operator classes, but it's not easy to do so. Ideally all logging could pass through PDFStreamEngine so that subclasses can more easily filter what they want. By using exceptions instead of logging for error cases, we allow more fine-grained management of exceptions. For example, in my own code I wish for a missing XObject to be a terminal failure, but it currently just results in a log message, and I have to implement a custom DrawObject operator and copy & paste over most of the code in order to catch this exception rather than logging it.

      I'm therefore going to move what little logging there is in the Operator classes over to PDFStreamEngine, and to throw custom exceptions (e.g. MissingResourceException) rather than writing silently to the log. The default implementation of processOperator in PDFStreamEngine will then catch these custom exceptions and simply write them to the log - keeping the current PDFBox behaviour unchanged. Only now consumers of PDFStreamEngine can override processOperator and do their own exception handling, e.g. I can choose to propagate MissingResourceException exception instead of logging it.

      This might be useful for Preflight too, as it often wants to throw errors where we would otherwise skip the offending object and just keep processing. Also it probably means that there will no longer be a need for to Preflight implement its own operators in those cases where it was done just to get stricter error handing.

      Attachments

        Activity

          People

            jahewson John Hewson
            jahewson John Hewson
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: