Logging breaks in packages that use PJLSA before setting up logging
Because cmmnbuild_dep_manager.Manager()
contains a call to logging.basicConfig()
, Python code that e.g. uses PJLSA and transitively ends up creating a Manager
before its own call to basicConfig()
cannot properly initialize logging for itself.
This ends up making logging messages mysteriously vanish.
Minimal example:
#!/usr/bin/env python
"""Example script for a third-party package that uses PJLSA.
Since this is an example, it cannot reasonably split into a launcher
module and the actual logic. The full dependency graph is:
this example
-> package showcased by the example
-> pjlsa
-> cmmnbuild_dep_manager
"""
import logging
import pjlsa
# If this script is being executed, use the JPype import system to make
# sure imports work. If this script is being imported, punt this task to
# whoever imports it.
if __name__ == "__main__":
with pjlsa.LSAClient(server="next").java_api():
# The real code doesn't import java.util but instead a module of
# this package that contains java imports at the top level.
import java.util
else:
import java.util
LOG = logging.getLogger(__name__)
# Code that makes use of the imported package: defining subclasses,
# functions with type hints, ...
def main():
"""Main function."""
logging.basicConfig(level=logging.DEBUG)
logging.info("does not appear")
logging.warning("does appear: %s", java.util)
if __name__ == "__main__":
main()