-
Notifications
You must be signed in to change notification settings - Fork 22
Description
Issue
Importing c2pa-python into our application has caused significant logging issues. Specifically the top of https://github.com/contentauth/c2pa-python/blob/v0.12.0/src/c2pa/lib.py overrides global logging configuration:
# Debug flag for library loading
DEBUG_LIBRARY_LOADING = False
# Configure logging
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s',
force=True # Force configuration even if already configured
)
logger = logging.getLogger(__name__)Calling logging.basicConfig(..., force=True) at import time forcefully resets the root logger configuration. This wipes any logging configuration already set by the host application. This causes significant issues in our production environment and is blocking us from integrating with the library.
This appears to have been introduced in https://github.com/contentauth/c2pa-python/releases/tag/v0.10.0.
Suggested Fix
Use a module-specific logger with NullHandler to avoid interfering with the global configuration.
Please see these best practices: https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library
- Note It is strongly advised that you do not log to the root logger in your library. Instead, use a logger with a unique and easily identifiable name, such as the name for your library’s top-level package or module. Logging to the root logger will make it difficult or impossible for the application developer to configure the logging verbosity or handlers of your library as they wish.
- Note It is strongly advised that you do not add any handlers other than NullHandler to your library’s loggers. This is because the configuration of handlers is the prerogative of the application developer who uses your library. The application developer knows their target audience and what handlers are most appropriate for their application: if you add handlers ‘under the hood’, you might well interfere with their ability to carry out unit tests and deliver logs which suit their requirements.
Here is an example:
import logging
# Create a module-specific logger
logger = logging.getLogger("c2pa")