def run(self) -> None:
        """Run logger's thread main loop.

        Keep consuming log queue until requested to quit through ``None`` special log record.
        """
        # switch to QueueHandler only when the thread was started
        with self.log_handler_lock:
            self._root_logger.addHandler(self._queue_handler)
            self._root_logger.removeHandler(self._proxy_handler)

        prev_record = None
        prev_hb_msg = ''

        while True:
            self._close_old_handlers()
            if TYPE_CHECKING:  # pragma: no cover
                assert self.log_handler is not None

            record = self._queue_handler.queue.get(True)
            # special message that indicates Patroni is shutting down
            if record is None:
                break

            if self._root_logger.level == logging.INFO:
                # messages like ``Lock owner: postgresql0; I am postgresql1`` will be shown only when stream doesn't
                # look normal. This is used to reduce chattiness of Patroni logs.
                if record.msg.startswith('Lock owner: '):
                    prev_record, record = record, None
                else:
                    if prev_record and prev_record.thread == record.thread:
                        if self._is_heartbeat_msg(record):
                            config = self._config or {}
                            deduplicate_heartbeat_logs = config.get('deduplicate_heartbeat_logs', False)
                            if record.msg == prev_hb_msg and deduplicate_heartbeat_logs:
                                record = None
                            else:
                                prev_hb_msg = record.msg
                        else:
                            self.log_handler.handle(prev_record)
                            prev_hb_msg = None
                        prev_record = None

            if record:
                self.log_handler.handle(record)

            self._queue_handler.queue.task_done()
Run logger's thread main loop.

        Keep consuming log queue until requested to quit through ``None`` special log record.
        
patroni/log.py