diff --git a/c2cwsgiutils/loader.py b/c2cwsgiutils/loader.py index 2d351420..5e833502 100644 --- a/c2cwsgiutils/loader.py +++ b/c2cwsgiutils/loader.py @@ -3,7 +3,7 @@ from plaster_pastedeploy import Loader as BaseLoader -from c2cwsgiutils import get_config_defaults +from c2cwsgiutils import get_config_defaults, get_logconfig_dict _LOG = logging.getLogger(__name__) @@ -19,3 +19,20 @@ def _get_defaults(self, defaults: Optional[dict[str, str]] = None) -> dict[str, def __repr__(self) -> str: """Get the object representation.""" return f'c2cwsgiutils.loader.Loader(uri="{self.uri}")' + + def setup_logging(self, defaults: Optional[dict[str, str]] = None) -> None: + """ + Set up logging via :func:`logging.config.fileConfig`. + Defaults are specified for the special ``__file__`` and ``here`` + variables, similar to PasteDeploy config loading. Extra defaults can + optionally be specified as a dict in ``defaults``. + + Arguments: + defaults: The defaults that will be used when passed to + :func:`logging.config.fileConfig`. + + """ + if "loggers" in self.get_sections(): + logging.config.dictConfig(get_logconfig_dict(self.uri.path)) + else: + logging.basicConfig()