Skip to content

Commit

Permalink
Pass package name to get the logging config
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Jul 18, 2024
1 parent 4a7c223 commit a2f6fb3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
13 changes: 9 additions & 4 deletions singer_sdk/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,24 +394,29 @@ def _load_yaml_logging_config(path: Traversable | Path) -> t.Any: # noqa: ANN40
return yaml.safe_load(f)


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


def _setup_logging(config: t.Mapping[str, t.Any]) -> None:
def _setup_logging(package: str, config: t.Mapping[str, t.Any]) -> None:
"""Setup logging.
Args:
package: The package name to get the logging configuration for.
config: A plugin configuration dictionary.
"""
logging.config.dictConfig(_load_yaml_logging_config(_get_default_config_path()))
path = _get_default_config_path(package)
logging.config.dictConfig(_load_yaml_logging_config(path))

config = config or {}
metrics_log_level = config.get(METRICS_LOG_LEVEL_SETTING, "INFO").upper()
Expand Down
2 changes: 1 addition & 1 deletion singer_sdk/plugin_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def __init__(
if self._is_secret_config(k):
config_dict[k] = SecretString(v)
self._config = config_dict
metrics._setup_logging(self.config) # noqa: SLF001
metrics._setup_logging(__package__, self.config) # noqa: SLF001
self.metrics_logger = metrics.get_metrics_logger()

self._validate_config(raise_errors=validate_config)
Expand Down

0 comments on commit a2f6fb3

Please sign in to comment.