Skip to content

Commit 153875e

Browse files
authored
Fix #37833: Use named logger instead of root logger in transforms/util.py (#37857)
Replace root logger calls (logging.info, logging.warning, etc.) with a module-level named logger (_LOGGER = logging.getLogger(__name__)) in apache_beam.transforms.util. This allows sdk_harness_log_level_overrides to properly control log levels for this module.
1 parent 180f3a6 commit 153875e

File tree

1 file changed

+10
-8
lines changed
  • sdks/python/apache_beam/transforms

1 file changed

+10
-8
lines changed

sdks/python/apache_beam/transforms/util.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@
9090
if TYPE_CHECKING:
9191
from apache_beam.runners.pipeline_context import PipelineContext
9292

93+
_LOGGER = logging.getLogger(__name__)
94+
9395
__all__ = [
9496
'BatchElements',
9597
'CoGroupByKey',
@@ -499,7 +501,7 @@ def get_secret_bytes(self) -> bytes:
499501
request={"name": secret_version_path})
500502
return response.payload.data
501503
except api_exceptions.NotFound:
502-
logging.info(
504+
_LOGGER.info(
503505
"Secret version %s not found. "
504506
"Creating new secret and version.",
505507
secret_version_path)
@@ -704,7 +706,7 @@ def expand(self, pcoll):
704706
try:
705707
coder = coder.as_deterministic_coder(self.label)
706708
except ValueError:
707-
logging.warning(
709+
_LOGGER.warning(
708710
'GroupByEncryptedKey %s: '
709711
'The key coder is not deterministic. This may result in incorrect '
710712
'pipeline output. This can be fixed by adding a type hint to the '
@@ -1025,7 +1027,7 @@ def finish_bundle(self):
10251027
self._batch = None
10261028
self._running_batch_size = 0
10271029
self._target_batch_size = self._batch_size_estimator.next_batch_size()
1028-
logging.info(
1030+
_LOGGER.info(
10291031
"BatchElements statistics: " + self._batch_size_estimator.stats())
10301032

10311033

@@ -1957,15 +1959,15 @@ def process(
19571959
log_line += ', pane_info=' + repr(pane_info)
19581960

19591961
if self.level == logging.DEBUG:
1960-
logging.debug(log_line)
1962+
_LOGGER.debug(log_line)
19611963
elif self.level == logging.INFO:
1962-
logging.info(log_line)
1964+
_LOGGER.info(log_line)
19631965
elif self.level == logging.WARNING:
1964-
logging.warning(log_line)
1966+
_LOGGER.warning(log_line)
19651967
elif self.level == logging.ERROR:
1966-
logging.error(log_line)
1968+
_LOGGER.error(log_line)
19671969
elif self.level == logging.CRITICAL:
1968-
logging.critical(log_line)
1970+
_LOGGER.critical(log_line)
19691971
else:
19701972
print(log_line)
19711973

0 commit comments

Comments
 (0)