Skip to content

DOC: How to handle / customize log records emitted by pypdf #2020

Open
@stefan6419846

Description

@stefan6419846

Explanation

According to

pypdf/pypdf/_utils.py

Lines 433 to 449 in 11ee648

def logger_warning(msg: str, src: str) -> None:
"""
Use this instead of logger.warning directly.
That allows people to overwrite it more easily.
## Exception, warnings.warn, logger_warning
- Exceptions should be used if the user should write code that deals with
an error case, e.g. the PDF being completely broken.
- warnings.warn should be used if the user needs to fix their code, e.g.
DeprecationWarnings
- logger_warning should be used if the user needs to know that an issue was
handled by pypdf, e.g. a non-compliant PDF being read in a way that
pypdf could apply a robustness fix to still read it. This applies mainly
to strict=False mode.
"""
logging.getLogger(src).warning(msg)

logger_warning is advertised to allow overwriting, but doing so proves to be more complicated than expected.

There basically are two reasons for this:

  1. The implementation is located at pypdf._utils.logger_warning, which usually marks an internal implementation and thus I would not assume this to be future-proof.
  2. The method usually is imported directly, as can be seen in
    logger_warning,
    for example. This requires patching each import separately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    EasyThis issue is a good starting point for first-time contributorshelp wantedWe appreciate help everywhere - this one might be an easy start!nf-documentationNon-functional change: Documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions