public static function createLoggingDelay(
        callable $delayFn,
        LoggerInterface $logger,
        $formatter = null
    ) {
        if (!$formatter) {
            $formatter = new Formatter(self::MSG_FORMAT);
        } elseif (!($formatter instanceof Formatter)) {
            $formatter = new Formatter($formatter);
        }

        return function (
            $retries,
            AbstractTransferEvent $event
        ) use ($delayFn, $logger, $formatter) {
            $delay = $delayFn($retries, $event);
            $logger->log(LogLevel::NOTICE, $formatter->format(
                $event->getRequest(),
                $event->getResponse(),
                $event instanceof ErrorEvent ? $event->getException() : null,
                [
                    'retries' => $retries + 1,
                    'delay'   => $delay
                ] + $event->getTransferInfo()
            ));
            return $delay;
        };
    }