Skip to content

Commit

Permalink
feat: Developers can now customize the default logging configuration …
Browse files Browse the repository at this point in the history
…for their taps/targets by overriding the `get_default_logging_config` method

Related:

* Closes #1373
  • Loading branch information
edgarrmondragon committed May 10, 2024
1 parent 46c14f6 commit 791f7a0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
21 changes: 7 additions & 14 deletions singer_sdk/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@

import yaml

from singer_sdk.helpers._resources import get_package_files

if t.TYPE_CHECKING:
from types import TracebackType

Expand Down Expand Up @@ -392,23 +390,18 @@ def _load_yaml_logging_config(path: Traversable | Path) -> t.Any: # noqa: ANN40
return yaml.safe_load(f)


def _get_default_config() -> t.Any: # noqa: ANN401
"""Get a logging configuration.
Returns:
A logging configuration.
"""
log_config_path = get_package_files("singer_sdk").joinpath("default_logging.yml")
return _load_yaml_logging_config(log_config_path)


def _setup_logging(config: t.Mapping[str, t.Any]) -> None:
def _setup_logging(
default_logging_config: dict[str, t.Any],
config: t.Mapping[str, t.Any],
) -> None:
"""Setup logging.
Args:
default_logging_config: A default
:py:std:label:`Python logging configuration dictionary`.
config: A plugin configuration dictionary.
"""
logging.config.dictConfig(_get_default_config())
logging.config.dictConfig(default_logging_config)

config = config or {}
metrics_log_level = config.get(METRICS_LOG_LEVEL_SETTING, "INFO").upper()
Expand Down
12 changes: 11 additions & 1 deletion singer_sdk/plugin_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
)
from singer_sdk.exceptions import ConfigValidationError
from singer_sdk.helpers._classproperty import classproperty
from singer_sdk.helpers._resources import get_package_files
from singer_sdk.helpers._secrets import SecretString, is_common_secret_key
from singer_sdk.helpers._util import read_json_file
from singer_sdk.helpers.capabilities import (
Expand Down Expand Up @@ -162,7 +163,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(self.get_default_logging_config(), self.config) # noqa: SLF001
self.metrics_logger = metrics.get_metrics_logger()

self._validate_config(raise_errors=validate_config)
Expand All @@ -178,6 +179,15 @@ def setup_mapper(self) -> None:
logger=self.logger,
)

def get_default_logging_config(self) -> t.Any: # noqa: ANN401, PLR6301
"""Get a default logging configuration for the plugin.
Returns:
A logging configuration.
"""
log_config_path = get_package_files("singer_sdk") / "default_logging.yml"
return metrics._load_yaml_logging_config(log_config_path) # noqa: SLF001

@property
def mapper(self) -> PluginMapper:
"""Plugin mapper for this tap.
Expand Down

0 comments on commit 791f7a0

Please sign in to comment.