Skip to content

Commit 76c967f

Browse files
Alfonso CastañoThe TensorFlow Datasets Authors
authored andcommitted
Catch exception of logging decorators
PiperOrigin-RevId: 641206038
1 parent 7689579 commit 76c967f

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

tensorflow_datasets/core/logging/__init__.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from typing import Any, Callable, Dict, List, Optional, Tuple, TypeVar
2424

2525
from absl import flags
26+
from absl import logging
2627
from tensorflow_datasets.core.logging import base_logger
2728
from tensorflow_datasets.core.logging import call_metadata
2829
from tensorflow_datasets.core.logging import logging_logger
@@ -155,11 +156,17 @@ def _finish_call(
155156
metadata.mark_end()
156157
for logger in _get_registered_loggers():
157158
method_name = self.__class__.__name__
158-
logger_method = getattr(logger, method_name)
159-
logger_method = self._fill_logger_method_kwargs(
160-
logger_method, metadata, instance, args, kwargs
161-
)
162-
self._call_logger_method(logger_method, args, kwargs)
159+
try:
160+
logger_method = getattr(logger, method_name)
161+
logger_method = self._fill_logger_method_kwargs(
162+
logger_method, metadata, instance, args, kwargs
163+
)
164+
self._call_logger_method(logger_method, args, kwargs)
165+
except Exception: # pylint: disable=broad-exception-caught
166+
logger_name = logger.__class__.__name__
167+
logging.exception(
168+
"Failed to call logger %s, method %s", logger_name, method_name
169+
)
163170

164171
@wrapt.decorator
165172
def __call__(self, function, instance, args, kwargs):

0 commit comments

Comments
 (0)