Skip to content

Commit

Permalink
Get module name programmatically
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Jul 18, 2024
1 parent a2f6fb3 commit a7d9cd3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
12 changes: 8 additions & 4 deletions singer_sdk/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,21 +394,25 @@ def _load_yaml_logging_config(path: Traversable | Path) -> t.Any: # noqa: ANN40
return yaml.safe_load(f)


def _get_default_config_path(package_name: str) -> Traversable:
def _get_default_config_path(package: str) -> Traversable:
"""Get a logging configuration.
Args:
package_name: The package name to get the logging configuration for.
package: The package name to get the logging configuration for.
Returns:
A logging configuration.
"""
filename = "default_logging.yml"
path = get_package_files(package_name) / filename
path = get_package_files(package) / filename
return path if path.is_file() else get_package_files("singer_sdk") / filename


def _setup_logging(package: str, config: t.Mapping[str, t.Any]) -> None:
def _setup_logging(
config: t.Mapping[str, t.Any],
*,
package: str | None = None,
) -> None:
"""Setup logging.
Args:
Expand Down
5 changes: 4 additions & 1 deletion singer_sdk/plugin_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ def __init__(
if self._is_secret_config(k):
config_dict[k] = SecretString(v)
self._config = config_dict
metrics._setup_logging(__package__, self.config) # noqa: SLF001
metrics._setup_logging( # noqa: SLF001
self.config,
package=self.__module__.split(".", maxsplit=1)[0],
)
self.metrics_logger = metrics.get_metrics_logger()

self._validate_config(raise_errors=validate_config)
Expand Down

0 comments on commit a7d9cd3

Please sign in to comment.