当前位置: 首页>>代码示例>>PHP>>正文


PHP Middleware::log方法代码示例

本文整理汇总了PHP中GuzzleHttp\Middleware::log方法的典型用法代码示例。如果您正苦于以下问题:PHP Middleware::log方法的具体用法?PHP Middleware::log怎么用?PHP Middleware::log使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GuzzleHttp\Middleware的用法示例。


在下文中一共展示了Middleware::log方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: register

 /**
  * Register method.
  */
 public function register()
 {
     // Configuring all guzzle clients.
     $this->app->bind(ClientInterface::class, function () {
         // Guzzle client
         return new Client(['handler' => $this->app->make(HandlerStack::class)]);
     });
     $this->app->alias(ClientInterface::class, Client::class);
     // Bind if needed.
     $this->app->bindIf(HandlerStack::class, function () {
         return HandlerStack::create();
     });
     // If resolved, by this SP or another, add some layers.
     $this->app->resolving(HandlerStack::class, function (HandlerStack $stack) {
         /** @var \DebugBar\DebugBar $debugBar */
         $debugBar = $this->app->make('debugbar');
         $stack->push(new Middleware(new Profiler($timeline = $debugBar->getCollector('time'))));
         $stack->unshift(new ExceptionMiddleware($debugBar->getCollector('exceptions')));
         /** @var \GuzzleHttp\MessageFormatter $formatter */
         $formatter = $this->app->make(MessageFormatter::class);
         $stack->unshift(GuzzleMiddleware::log($debugBar->getCollector('messages'), $formatter));
         // Also log to the default PSR logger.
         if ($this->app->bound(LoggerInterface::class)) {
             $logger = $this->app->make(LoggerInterface::class);
             // Don't log to the same logger twice.
             if ($logger === $debugBar->getCollector('messages')) {
                 return;
             }
             // Push the middleware on the stack.
             $stack->unshift(GuzzleMiddleware::log($logger, $formatter));
         }
     });
 }
开发者ID:hannesvdvreken,项目名称:guzzle-debugbar,代码行数:36,代码来源:ServiceProvider.php

示例2: initClient

 private function initClient()
 {
     $handlerStack = HandlerStack::create();
     $handlerStack->push(MiddlewareBuilder::factoryForPing($this->logger, self::MAX_RETRIES));
     $handlerStack->push(Middleware::log($this->logger, new MessageFormatter('{hostname} {req_header_User-Agent} - [{ts}] \\"{method} {resource} {protocol}/{version}\\" {code} {res_header_Content-Length}')));
     $this->client = new \GuzzleHttp\Client(['base_uri' => $this->storageApi->getApiUrl(), 'handler' => $handlerStack]);
 }
开发者ID:keboola,项目名称:orchestrator-bundle,代码行数:7,代码来源:PingClient.php

示例3: __construct

 public function __construct($parameters = [], GuzzleHttp\ClientInterface $httpClient = null)
 {
     $this->configure($parameters);
     $stack = GuzzleHttp\HandlerStack::create();
     if ($this->logger instanceof LoggerInterface) {
         $stack->push(GuzzleHttp\Middleware::log($this->logger, new GuzzleHttp\MessageFormatter(GuzzleHttp\MessageFormatter::DEBUG)));
     }
     $this->httpClient = new GuzzleHttp\Client(['handler' => $stack]);
 }
开发者ID:glebvga,项目名称:techfinancials-api-client,代码行数:9,代码来源:ApiClient.php

示例4: create

 /**
  * Create and configure a http curl client.
  *
  * @param array $settings additional settings
  *
  * @return Client
  */
 public function create(array $settings = [])
 {
     $stack = null;
     $settings = $this->platform->toArray() + $settings;
     if ($this->getLogger() instanceof LoggerInterface) {
         $stack = HandlerStack::create();
         $stack->push(Middleware::log($this->getLogger(), new MessageFormatter('{request} - {response}')));
     }
     return new Client(['base_url' => (string) $settings['url'], 'handler' => $stack, 'exceptions' => false, 'timeout' => (double) $settings['responseTimeout'], 'connection_timeout' => (double) $settings['connectionTimeout']]);
 }
开发者ID:webservices-nl,项目名称:platform-connector,代码行数:17,代码来源:GuzzleClientFactory.php

示例5: __construct

 public function __construct($base = null)
 {
     if (!$this->client) {
         $logger = new Logger('mylogger');
         $logger->pushHandler(new StreamHandler(__DIR__ . '/../logs/log.txt'));
         $formatter = new MessageFormatter(MessageFormatter::DEBUG);
         $handler = HandlerStack::create()->push(Middleware::log($logger, $formatter));
         $this->client = new Client(['base_uri' => $base ?: 'https://api.github.com', 'handler' => $handler]);
     }
 }
开发者ID:appkr,项目名称:guzzle-starter,代码行数:10,代码来源:Github.php

示例6: getHttpClient

 /**
  * Getter for the HTTP client.
  *
  * @return Client
  */
 protected function getHttpClient()
 {
     if ($this->client === null) {
         if ($this->logger instanceof LoggerInterface) {
             $this->handlerStack->push(Middleware::log($this->logger, $this->messageFormatter, $this->logLevel));
         }
         $this->options['handler'] = $this->handlerStack;
         $this->client = new Client($this->options);
     }
     return $this->client;
 }
开发者ID:kevintweber,项目名称:gauges,代码行数:16,代码来源:Request.php

示例7: __construct

 public function __construct($debug, LoggerInterface $httpLogAdapter)
 {
     $this->debug = $debug;
     $this->httpLogAdapter = $httpLogAdapter;
     $config = [];
     if ($this->debug) {
         $config['handler'] = HandlerStack::create();
         $config['handler']->push(Middleware::log($this->httpLogAdapter, new MessageFormatter(MessageFormatter::DEBUG)));
     }
     parent::__construct($config);
 }
开发者ID:mattmerrill,项目名称:infusionsoft-php,代码行数:11,代码来源:GuzzleHttpClient.php

示例8: getHttpClient

 protected function getHttpClient()
 {
     if (!is_null($this->httpClient)) {
         return $this->httpClient;
     }
     $stack = GuzzleHttp\HandlerStack::create();
     if ($this->logger instanceof LoggerInterface) {
         $stack->push(GuzzleHttp\Middleware::log($this->logger, new GuzzleHttp\MessageFormatter(GuzzleHttp\MessageFormatter::DEBUG)));
     }
     $this->httpClient = new GuzzleHttp\Client(['base_uri' => $this->getUrl(), 'handler' => $stack]);
     return $this->httpClient;
 }
开发者ID:alexander-emelyanov,项目名称:tradologic-api-client,代码行数:12,代码来源:ApiClient.php

示例9: prepareConfig

 public static function prepareConfig($config, $logger)
 {
     if (!isset($config['base_uri']) && isset($config['base_url'])) {
         $config['base_uri'] = $config['base_url'];
     }
     $stack = HandlerStack::create();
     if ($logger) {
         if ($logger instanceof \Psr\Log\LoggerInterface) {
             $stack->push(Middleware::log($logger, new MessageFormatter(MessageFormatter::DEBUG)));
         } else {
             throw new \Exception('Logger must implement PsrLogLoggerInterface');
         }
     }
     $config['handler'] = $stack;
     return $config;
 }
开发者ID:Synerise,项目名称:PHP-SDK,代码行数:16,代码来源:Guzzle6.php

示例10: create

 public static function create($access_token)
 {
     $google_api_key = getenv('GOOGLE_API_KEY');
     $google_end_point = getenv('GOOGLE_ENDPOINT');
     if (!$google_api_key or !$google_end_point) {
         throw new \Exception("Google is not configured");
     }
     $handler = HandlerStack::create();
     $handler->push(Middleware::log(new Logger('console'), new MessageFormatter('{method} {uri} {req_headers} {req_body}')));
     $google_rest_client = new RESTAdapter\RESTClient($google_end_point, $handler);
     $google_maps = new Google\Maps($google_api_key, $google_rest_client);
     $instagram_end_point = getenv('INSTAGRAM_ENDPOINT');
     if (!$instagram_end_point) {
         throw new \Exception('Instagram is not configured');
     }
     $instagram_rest_client = new RESTAdapter\RESTClient($instagram_end_point, $handler);
     $instagram_media_endpoint = new Instagram\MediaEndPoint($access_token, $instagram_rest_client);
     return new MediaInspector($instagram_media_endpoint, $google_maps);
 }
开发者ID:emigm,项目名称:media-inspector,代码行数:19,代码来源:MediaInspectorFactory.php

示例11: getHttpHandler

 /**
  * @return \Aws\Handler\GuzzleV6\GuzzleHandler
  */
 private function getHttpHandler()
 {
     $guzzleStack = \GuzzleHttp\HandlerStack::create();
     $guzzleStack->push(\GuzzleHttp\Middleware::retry(function ($retries, \GuzzleHttp\Psr7\Request $request, \GuzzleHttp\Psr7\Response $response = null, \GuzzleHttp\Exception\RequestException $exception = null) {
         if ($retries >= 5) {
             return false;
         }
         if ($exception instanceof \GuzzleHttp\Exception\ConnectException) {
             return true;
         }
         if ($response) {
             if ($response->getStatusCode() == 400) {
                 return true;
             }
         }
         return false;
     }));
     if ($this->output && $this->output->isVeryVerbose()) {
         $guzzleStack->push(\GuzzleHttp\Middleware::log(new \Monolog\Logger('main'), new \GuzzleHttp\MessageFormatter('[{code}] {req_body}')));
     }
     return new \Aws\Handler\GuzzleV6\GuzzleHandler(new \GuzzleHttp\Client(['handler' => $guzzleStack]));
 }
开发者ID:aoepeople,项目名称:stackformation,代码行数:25,代码来源:Manager.php

示例12: execute

 /**
  * Execute an XML request to Intacct
  *
  * @param XMLWriter $xml
  * @return ResponseInterface
  */
 private function execute($xml)
 {
     //this is used for retry logic
     $calls = [];
     $decider = function ($retries, $request, $response, $error) use(&$calls) {
         $calls[] = func_get_args();
         if (count($calls) > $this->maxRetries) {
             return false;
         }
         if ($error instanceof \GuzzleHttp\Exception\ServerException) {
             //retry if receiving http 5xx error codes
             $response = $error->getResponse();
             if (in_array($response->getStatusCode(), $this->noRetryServerErrorCodes) === true) {
                 return false;
             } else {
                 return true;
             }
         }
         //do not retry otherwise
         return false;
     };
     //setup the handler
     if ($this->mockHandler instanceof MockHandler) {
         $handler = HandlerStack::create($this->mockHandler);
     } else {
         $handler = HandlerStack::create();
     }
     //add the retry logic before the http_errors middleware
     $handler->before('http_errors', Middleware::retry($decider), 'retry_logic');
     //push the history middleware to the top of the stack
     $handler->push(Middleware::history($this->history));
     if ($this->logger) {
         //push the logger middleware to the top of the stack
         $handler->push(Middleware::log($this->logger, $this->logMessageFormat, $this->logLevel));
     }
     $client = new Client(['handler' => $handler]);
     $options = ['body' => $xml->flush(), 'verify' => $this->getVerifySSL(), 'headers' => ['content-type' => self::REQUEST_CONTENT_TYPE, 'User-Agent' => $this->getUserAgent()]];
     $response = $client->post($this->endpointURL, $options);
     return $response;
 }
开发者ID:Intacct,项目名称:intacct-sdk-php,代码行数:46,代码来源:RequestHandler.php

示例13: Logger

/**
 * Attention: This example script will modify the test library! Do not run this script
 * unless you are prepared for that.
 */
require_once __DIR__ . '/../vendor/autoload.php';
use Seafile\Client\Resource\Directory;
use Seafile\Client\Resource\File;
use Seafile\Client\Resource\Library;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use GuzzleHttp\MessageFormatter;
use Monolog\Logger;
use Seafile\Client\Http\Client;
$logger = new Logger('Logger');
$stack = HandlerStack::create();
$stack->push(Middleware::log($logger, new MessageFormatter("{hostname} {req_header_Authorization} - {req_header_User-Agent} - [{date_common_log}] \"{method} {host}{target} HTTP/{version}\" {code} {res_header_Content-Length} req_body: {req_body} response_body: {res_body}")));
/**
 * Example:
 * {"token": "your_token"}
 */
$tokenFile = getenv("HOME") . "/.seafile-php-sdk/api-token.json";
/**
 * Example:
 * {
 *   "baseUri": "https://your.seafile-server.example.com",
 *   "testLibId": "ID of an encrypted library",
 *   "testLibPassword": "Password of that encrypted library"
 * }
 */
$cfgFile = getenv("HOME") . "/.seafile-php-sdk/cfg.json";
if (!is_readable($tokenFile)) {
开发者ID:rene-s,项目名称:Seafile-PHP-SDK,代码行数:31,代码来源:example.php

示例14: createService

 /**
  * This method will return an OpenStack service ready fully built and ready for use. There is
  * some initial setup that may prohibit users from directly instantiating the service class
  * directly - this setup includes the configuration of the HTTP client's base URL, and the
  * attachment of an authentication handler.
  *
  * @param $serviceName          The name of the service as it appears in the OpenStack\* namespace
  * @param $serviceVersion       The major version of the service
  * @param array $serviceOptions The service-specific options to use
  *
  * @return \OpenStack\Common\Service\ServiceInterface
  *
  * @throws \Exception
  */
 public function createService($serviceName, $serviceVersion, array $serviceOptions = [])
 {
     $options = $this->mergeOptions($serviceOptions);
     if (!isset($options['identityService'])) {
         $httpClient = $this->httpClient($options['authUrl'], HandlerStack::create());
         $options['identityService'] = Service::factory($httpClient);
     }
     if (!isset($options['authHandler'])) {
         $options['authHandler'] = function () use($options) {
             return $options['identityService']->generateToken($options);
         };
     }
     if (!isset($options['httpClient']) || !$options['httpClient'] instanceof ClientInterface) {
         if (strcasecmp($serviceName, 'identity') === 0) {
             $baseUrl = $options['authUrl'];
             $stack = $this->getStack($options['authHandler']);
         } else {
             list($token, $baseUrl) = $options['identityService']->authenticate($options);
             $stack = $this->getStack($options['authHandler'], $token);
         }
         if (!empty($options['debugLog'])) {
             $stack->push(GuzzleMiddleware::log($options['logger'], $options['messageFormatter']));
         }
         $options['httpClient'] = $this->httpClient($baseUrl, $stack);
     }
     list($apiClass, $serviceClass) = $this->getClasses($serviceName, $serviceVersion);
     return new $serviceClass($options['httpClient'], new $apiClass());
 }
开发者ID:alewitt,项目名称:openstack,代码行数:42,代码来源:Builder.php

示例15: createMiddlewareLogCallback

 /**
  * @codeCoverageIgnore
  *
  * @param \Psr\Log\LoggerInterface $logger
  * @param \GuzzleHttp\MessageFormatter $messageFormatter
  * @param string $logLevel
  * @return callable
  */
 protected function createMiddlewareLogCallback($logger, $messageFormatter, $logLevel = LogLevel::INFO)
 {
     return Middleware::log($logger, $messageFormatter, $logLevel);
 }
开发者ID:subscribepro,项目名称:subscribepro-php,代码行数:12,代码来源:Http.php


注:本文中的GuzzleHttp\Middleware::log方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。