Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement basic library logging #231

Merged
merged 11 commits into from
Apr 14, 2024
Merged

Conversation

peternowee
Copy link
Member

From the commit message:

pydot currently prints some error messages to standard output (stdout). Printing anything is considered bad practice for libraries (SO, reddit). This becomes even more disturbing if the prints contain long Graphviz output or DOT strings.

This commit lays the groundwork for switching from printing to logging by providing a basic library logging setup and some user documentation on how to read the logs. Later commits will replace the actual printing by logging.

Discussion: #171.

Additional remarks:

CC: @ankostis

pydot currently prints some error messages to standard output
(`stdout`). Printing anything is considered bad practice for libraries
[1] [2]. This becomes even more disturbing if the prints contain long
Graphviz output or DOT strings.

[1]: https://stackoverflow.com/questions/4201856/error-handling-strategies-in-a-shared-library-c
[2]: https://www.reddit.com/r/C_Programming/comments/97ebfj/redirect_stdout_and_stderr_to_a_buffer/e47n9kh/

This commit lays the groundwork for switching from printing to logging
by providing a basic library logging setup and some user documentation
on how to read the logs. Later commits will replace the actual printing
by logging.

Discussed in pydot#171 and pydot#231.
Notes:
- I am aware that in `__init__.py`, the placement of the logger
  registration before the imports of the submodules leads to additional
  warnings in code checkers:
  From pylint:
      C0413: Import "from pydot.exceptions import *" should be placed at the top of the module (wrong-import-position)
      C0413: Import "from pydot.core import *" should be placed at the top of the module (wrong-import-position)
  From flake8:
      E402 module level import not at top of file
      E402 module level import not at top of file
  I do not really see how we can avoid this if we want to log a first
  message early during pydot initialization. Also note that the
  concerned imports are all pydot "internal" submodules and that for
  `__init__.py` importing those is its main task, so this having a
  central place in the file does not seem unnatural.
- In `test/pydot_unittest.py`, added a final `importlib.reload(pydot)`
  to prevent subsequent tests from failing, probably caused by one of
  the caveats mentioned in:
  https://docs.python.org/3/library/importlib.html#importlib.reload
Notes:
- Removed the hint that the parent logger can be used to control all
  pydot loggers, because this is basic knowledge covered by the Python
  documentation to which we already refer.
@peternowee
Copy link
Member Author

Rebased on master. The first commit is just a minimal rebase of the original. Additional changes are in the remaining commits:

  • Reformatting by Black.
  • Use __name__ to name the loggers. (@ankostis: This follows your suggestion of last year, in issue #171 to use __name__ instead of hard-coded logger names. The recent merging of the new project structure finally made this possible.)
  • Add a parent logger to __init__.py and change the order in which the loggers are registered.
  • Documentation improvements.

See commits and commit messages for details.

All commits titled "Fixup: ...." will be squashed into the first commit ("Implement basic library logging") on merging. Only the last commit will remain separate, because it contains some README cleanup not related to logging.

Copy link

github-actions bot commented Feb 8, 2024

This pull request has conflicts, please resolve those so that the changes can be evaluated.

Copy link

All conflicts have been resolved, thanks!

@lkk7 lkk7 force-pushed the feature/logging branch 2 times, most recently from 5c75f41 to db95e2e Compare April 14, 2024 16:01
@lkk7 lkk7 merged commit 425d847 into pydot:master Apr 14, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants