### Apache Airflow version

2.2.2 (latest released)

### Operating System

Linux-5.4.0-1056-azure-x86_64-with-glibc2.2.5

### Versions of Apache Airflow Providers

_No response_

### Deployment

Other Docker-based deployment

### Deployment details

kubernetes 1.21.2 (AKS)

### What happened

**DAG using logging class produce stack overflow and abort task.** It seems like a bug in /home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py 

**ENV:**
AIRFLOW__CORE__HIDE_SENSITIVE_VAR_CONN_FIELDS="False"

**Dag Code fragment:**

log_stream = StringIO()
logging.basicConfig(stream=log_stream, level=logging.DEBUG)

logger = logging.getLogger("airflow.task")
logger.addHandler(logging.StreamHandler(log_stream))
...
logger.info("------------------------------ ------------------- ------------------------------")

#####

**Log in worker pod:**

```
Fatal Python error: Cannot recover from stack overflow.
Python runtime state: initialized

Current thread 0x00007fbf8d8190c0 (most recent call first):
  File "/usr/local/lib/python3.8/posixpath.py", line 42 in _get_sep
  File "/usr/local/lib/python3.8/posixpath.py", line 143 in basename
  File "/usr/local/lib/python3.8/logging/__init__.py", line 322 in __init__
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1556 in makeRecord
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1587 in _log
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1458 in warning
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 215 in _redact
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 208 in <genexpr>
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 208 in _redact
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 231 in redact
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 164 in filter
  File "/usr/local/lib/python3.8/logging/__init__.py", line 811 in filter
  File "/usr/local/lib/python3.8/logging/__init__.py", line 950 in handle
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1661 in callHandlers
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1599 in handle
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1589 in _log
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1458 in warning
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 215 in _redact
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 208 in <genexpr>
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 208 in _redact
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 231 in redact
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 164 in filter
  File "/usr/local/lib/python3.8/logging/__init__.py", line 811 in filter
  File "/usr/local/lib/python3.8/logging/__init__.py", line 950 in handle
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1661 in callHandlers
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1599 in handle
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1589 in _log
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1458 in warning
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 215 in _redact
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 208 in <genexpr>
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 208 in _redact
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 231 in redact
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 164 in filter
  File "/usr/local/lib/python3.8/logging/__init__.py", line 811 in filter
  File "/usr/local/lib/python3.8/logging/__init__.py", line 950 in handle
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1661 in callHandlers
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1599 in handle
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1589 in _log
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1458 in warning
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 215 in _redact
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 208 in <genexpr>
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 208 in _redact
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 208 in <genexpr>
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 208 in _redact
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 231 in redact
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 164 in filter
  File "/usr/local/lib/python3.8/logging/__init__.py", line 811 in filter
  File "/usr/local/lib/python3.8/logging/__init__.py", line 950 in handle
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1661 in callHandlers
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1599 in handle
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1589 in _log
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1458 in warning
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 215 in _redact
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 231 in redact
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 164 in filter
  File "/usr/local/lib/python3.8/logging/__init__.py", line 811 in filter
  File "/usr/local/lib/python3.8/logging/__init__.py", line 950 in handle
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1661 in callHandlers
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1599 in handle
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1589 in _log
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1458 in warning
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 215 in _redact
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 208 in <genexpr>
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 208 in _redact
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 231 in redact
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 164 in filter
  File "/usr/local/lib/python3.8/logging/__init__.py", line 811 in filter
  File "/usr/local/lib/python3.8/logging/__init__.py", line 950 in handle
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1661 in callHandlers
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1599 in handle
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1589 in _log
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1458 in warning
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 215 in _redact
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 208 in <genexpr>
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 208 in _redact
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 231 in redact
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 164 in filter
  File "/usr/local/lib/python3.8/logging/__init__.py", line 811 in filter
  File "/usr/local/lib/python3.8/logging/__init__.py", line 950 in handle
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1661 in callHandlers
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1599 in handle
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1589 in _log
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1458 in warning
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 215 in _redact
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 208 in <genexpr>
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 208 in _redact
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 231 in redact
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 164 in filter
  File "/usr/local/lib/python3.8/logging/__init__.py", line 811 in filter
  File "/usr/local/lib/python3.8/logging/__init__.py", line 950 in handle
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1661 in callHandlers
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1599 in handle
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1589 in _log
  File "/usr/local/lib/python3.8/logging/__init__.py", line 1458 in warning
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 215 in _redact
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 208 in <genexpr>
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 208 in _redact
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 231 in redact
  File "/home/airflow/.local/lib/python3.8/site-packages/airflow/utils/log/secrets_masker.py", line 164 in filter
  File "/usr/local/lib/python3.8/logging/__init__.py", line 811 in filter
```




### What you expected to happen

_No response_

### How to reproduce

_No response_

### Anything else

_No response_

### Are you willing to submit PR?

- [ ] Yes I am willing to submit a PR!

### Code of Conduct

- [X] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)

airflow/utils/log/secrets_masker.py
#
#
"""Mask sensitive information from logs"""
import collections
import logging
import re
from typing import TYPE_CHECKING, Iterable, Optional, Set, TypeVar, Union
from airflow.compat.functools import cache, cached_property
if TYPE_CHECKING:
    from airflow.typing_compat import RePatternType
    RedactableItem = TypeVar('RedactableItem')
log = logging.getLogger(__name__)
DEFAULT_SENSITIVE_FIELDS = frozenset(
    {
        'access_token',