protected function setLogHandler(\GuzzleHttp\HandlerStack $handlerStack, callable $logHandler)
    {
        try {
            $handlerStack->after('history', $logHandler, 'logger');
        } catch (\InvalidArgumentException $e) {
            try {
                $handlerStack->before('allow_redirects', $logHandler, 'logger');
            } catch (\InvalidArgumentException $e) {
                $handlerStack->push($logHandler, 'logger');
            }
        }

        return $this;
    }