Skip to content

Commit

Permalink
Use log.exception where more economical than log.error (#27517)
Browse files Browse the repository at this point in the history
When we do log.error(..., exc_info=True), then log.exception is cleaner.
  • Loading branch information
dstandish authored Nov 7, 2022
1 parent 6307dc1 commit 8c15b0a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
2 changes: 1 addition & 1 deletion airflow/providers/alibaba/cloud/log/oss_task_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def hook(self):
try:
return OSSHook(oss_conn_id=remote_conn_id)
except Exception as e:
self.log.error(e, exc_info=True)
self.log.exception(e)
self.log.error(
'Could not create an OSSHook with connection id "%s". '
"Please make sure that airflow[oss] is installed and "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -631,5 +631,5 @@ def __exit__(self, exctype, excinst, exctb):
if caught_error:
self.exception = excinst
logger = logging.getLogger(__name__)
logger.error(str(excinst), exc_info=True)
logger.exception(excinst)
return caught_error
2 changes: 1 addition & 1 deletion airflow/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def wrapper(_self, stat=None, *args, **kwargs):
stat = handler_stat_name_func(stat)
return fn(_self, stat, *args, **kwargs)
except InvalidStatsNameException:
log.error('Invalid stat name: %s.', stat, exc_info=True)
log.exception('Invalid stat name: %s.', stat)
return None

return cast(T, wrapper)
Expand Down
10 changes: 4 additions & 6 deletions tests/providers/cncf/kubernetes/operators/test_kubernetes_pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -898,10 +898,8 @@ def test_mark_checked_if_not_deleted(self, mock_patch_already_checked, mock_dele
mock_delete_pod.assert_not_called()


def test__suppress():
with patch("logging.Logger.error") as mock_error:
def test__suppress(caplog):
with _suppress(ValueError):
raise ValueError("failure")

with _suppress(ValueError):
raise ValueError("failure")

mock_error.assert_called_once_with("failure", exc_info=True)
assert "ValueError: failure" in caplog.text

0 comments on commit 8c15b0a

Please sign in to comment.