diff --git a/utils/logging_config.py b/utils/logging_config.py new file mode 100644 index 0000000..0f5ef8f --- /dev/null +++ b/utils/logging_config.py @@ -0,0 +1,18 @@ +import logging + +LOG_FORMAT = "%(asctime)s %(levelname)s [%(name)s] %(message)s" +logging.basicConfig(level=logging.INFO, format=LOG_FORMAT) +# reduce noise from overly-verbose libraries +logging.getLogger("urllib3").setLevel(logging.WARNING) +logging.getLogger("PIL").setLevel(logging.WARNING) + +# Expose a convenience function for other modules to use when they want +# to ensure logging is configured (idempotent). + +def configure_logging(level: int = logging.INFO) -> None: + """Configure root logging for the application. + + This is safe to call multiple times; subsequent calls will not reconfigure + handlers if they've already been set up by basicConfig. + """ + logging.getLogger().setLevel(level)