def _get_json_formatter(self, logformat: type_logformat, dateformat: Optional[str],
                            static_fields: Dict[str, Any]) -> logging.Formatter:
        """Returns a logging formatter that outputs JSON formatted messages.

        .. note::
            If :mod:`pythonjsonlogger` library is not installed, prints an error message and returns
            a plain log formatter instead.

        :param logformat: Specifies the log fields and their key names in the JSON log message.
        :param dateformat: The format of the timestamp in the log messages.
        :param static_fields: A dictionary of static fields that are added to every log message.

        :returns: A logging formatter object that can be used to format log records as JSON strings.
        """

        if isinstance(logformat, str):
            jsonformat = logformat
            rename_fields = {}
        elif isinstance(logformat, list):
            logformat = cast(List[Any], logformat)
            log_fields: List[str] = []
            rename_fields: Dict[str, str] = {}

            for field in logformat:
                if isinstance(field, str):
                    log_fields.append(field)
                elif isinstance(field, dict):
                    field = cast(Dict[str, Any], field)
                    for original_field, renamed_field in field.items():
                        if isinstance(renamed_field, str):
                            log_fields.append(original_field)
                            rename_fields[original_field] = renamed_field
                        else:
                            _LOGGER.warning(
                                'Expected renamed log field to be a string, but got "%s"',
                                _type(renamed_field)
                            )

                else:
                    _LOGGER.warning(
                        'Expected each item of log format to be a string or dictionary, but got "%s"',
                        _type(field)
                    )

            if len(log_fields) > 0:
                jsonformat = ' '.join([f'%({field})s' for field in log_fields])
            else:
                jsonformat = PatroniLogger.DEFAULT_FORMAT
        else:
            jsonformat = PatroniLogger.DEFAULT_FORMAT
            rename_fields = {}
            _LOGGER.warning('Expected log format to be a string or a list, but got "%s"', _type(logformat))

        try:
            try:
                from pythonjsonlogger import json as jsonlogger  # pyright: ignore
            except ImportError:  # pragma: no cover
                from pythonjsonlogger import jsonlogger
                if hasattr(jsonlogger, 'RESERVED_ATTRS') \
                        and 'taskName' not in jsonlogger.RESERVED_ATTRS:  # pyright: ignore [reportPrivateImportUsage]
                    # compatibility with python 3.12, that added a new attribute to LogRecord
                    jsonlogger.RESERVED_ATTRS += ('taskName',)  # pyright: ignore

            return jsonlogger.JsonFormatter(  # pyright: ignore [reportPrivateImportUsage]
                jsonformat,
                dateformat,
                rename_fields=rename_fields,
                static_fields=static_fields
            )
        except ImportError as e:
            _LOGGER.error('Failed to import "python-json-logger" library: %r. Falling back to the plain logger', e)
        except Exception as e:
            _LOGGER.error('Failed to initialize JsonFormatter: %r. Falling back to the plain logger', e)

        return self._get_plain_formatter(jsonformat, dateformat)
Returns a logging formatter that outputs JSON formatted messages.

        .. note::
            If :mod:`pythonjsonlogger` library is not installed, prints an error message and returns
            a plain log formatter instead.

        :param logformat: Specifies the log fields and their key names in the JSON log message.
        :param dateformat: The format of the timestamp in the log messages.
        :param static_fields: A dictionary of static fields that are added to every log message.

        :returns: A logging formatter object that can be used to format log records as JSON strings.
        
patroni/log.py