def drain(self):
        """
        Log any/all outstanding messages/data.
        NOTE: can run indefinitely if data is arriving constantly.
        """
        logger.warning("Draining interface...")
        drained = bytearray()
        finished = False

        while not finished:
            byte_ = self.impl.read(1)
            drained.extend(byte_)
            finished = byte_ == b''

            if finished or byte_ == b'\n' or len(drained) > 256:
                try:
                    device_logger.warning(drained.decode('utf-8'))
                except Exception as e:
                    # Dump the bytes raw and as hex if decoding as utf-8 failed
                    device_logger.warning("Raw:")
                    device_logger.warning(drained)
                    device_logger.warning("----")
                    device_logger.warning("Hex dump:")
                    device_logger.warning(drained.hex())

                # Clear and loop to continue collecting
                drained.clear()

        Log any/all outstanding messages/data.
        NOTE: can run indefinitely if data is arriving constantly.
        
electrum/plugins/jade/jadepy/jade.py