|
18 | 18 |
|
19 | 19 | import logging
|
20 | 20 | import sys
|
| 21 | +from types import MethodType |
21 | 22 |
|
22 | 23 |
|
23 | 24 | def get_sagemaker_config_logger():
|
@@ -46,7 +47,7 @@ def get_sagemaker_config_logger():
|
46 | 47 | # if a handler is being added, we dont want the root handler to also process the same events
|
47 | 48 | sagemaker_config_logger.propagate = False
|
48 | 49 |
|
49 |
| - return sagemaker_config_logger |
| 50 | + return non_repeating_logger(sagemaker_config_logger) |
50 | 51 |
|
51 | 52 |
|
52 | 53 | def _log_sagemaker_config_single_substitution(source_value, config_value, config_key_path: str):
|
@@ -197,3 +198,25 @@ def _log_sagemaker_config_merge(
|
197 | 198 | else:
|
198 | 199 | # nothing was specified in the config and nothing is being automatically applied
|
199 | 200 | logger.debug("Skipped value because no value defined\n config key = %s", config_key_path)
|
| 201 | + |
| 202 | + |
| 203 | +def non_repeating_logger(logger: logging.Logger) -> logging.Logger: |
| 204 | + """Patch the logger to remove repeating info logs. |
| 205 | +
|
| 206 | + Args: |
| 207 | + logger (logging.Logger): the logger to be patched |
| 208 | +
|
| 209 | + Returns: |
| 210 | + (logging.Logger): the patched logger |
| 211 | + """ |
| 212 | + _caches = set() |
| 213 | + _old_impl = logger.info |
| 214 | + |
| 215 | + def _new_impl(_, msg, *args, **kwargs): |
| 216 | + key = f"{msg}:{args}" |
| 217 | + if key not in _caches: |
| 218 | + _old_impl(msg, *args, **kwargs) |
| 219 | + _caches.add(key) |
| 220 | + |
| 221 | + logger.info = MethodType(_new_impl, logger) |
| 222 | + return logger |
0 commit comments