Skip to content

Commit

Permalink
Merge pull request #14 from youzan/hotfix/reduce_framework_log
Browse files Browse the repository at this point in the history
移除框架的http proxy日志
  • Loading branch information
xu42 authored Jan 9, 2020
2 parents bca89bf + 0a3e31f commit 89563ce
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
21 changes: 21 additions & 0 deletions src/Component/BaseComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,21 @@ abstract class BaseComponent
*/
protected $_container;

/**
* 是否是Debug模式
* @var bool
*/
protected $_debug;

public function __construct(ContainerInterface $container)
{
$this->_container = $container;

if (defined('YZCLOUD_BOOT_DEBUG')) {
$this->_debug = boolval(YZCLOUD_BOOT_DEBUG);
} else {
$this->_debug = false;
}
}

/**
Expand Down Expand Up @@ -46,5 +58,14 @@ protected function getEnvUtil(): EnvUtil
return $this->_container->get('envUtil');
}

/**
* 是否是debug模式
* @return bool
*/
protected function isDebug(): bool
{
return $this->_debug;
}


}
32 changes: 24 additions & 8 deletions src/Http/HttpClientWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,17 @@ public function get(string $url, array $headers = null): HttpClientResponse
list($scheme, $user, $pass, $host, $port, $path, $query) = $this->parseUrl($url);

if (empty($this->proxy) or $this->isInnerService($host)) {
$this->getLog()->info(sprintf("Get directly, url: %s, headers: %s", $url, json_encode($headers)));
if ($this->isDebug()) {
$this->getLog()->info(sprintf("Get directly, url: %s, headers: %s", $url, json_encode($headers)));
}
return $this->doRequest('GET', $url, false, $scheme, $headers, null);
}

$realRequestUrl = $this->parseRealRequestUrl($path, $query);
$realRequestHeaders = $this->parseHeaders($headers, $host, $user, $pass, $port, $scheme);
$this->getLog()->info(sprintf("Get through proxy, url: %s, headers: %s", $realRequestUrl, json_encode($realRequestHeaders)));
if ($this->isDebug()) {
$this->getLog()->info(sprintf("Get through proxy, url: %s, headers: %s", $realRequestUrl, json_encode($realRequestHeaders)));
}

return $this->doRequest('GET', $realRequestUrl, true, $scheme, $realRequestHeaders, null);
}
Expand Down Expand Up @@ -193,13 +197,17 @@ public function post(string $url, array $headers = null, $body = null): HttpClie
list($scheme, $user, $pass, $host, $port, $path, $query) = $this->parseUrl($url);

if (empty($this->proxy) or $this->isInnerService($host)) {
$this->getLog()->info(sprintf("Post directly, url: %s, headers: %s", $url, json_encode($headers)));
if ($this->isDebug()) {
$this->getLog()->info(sprintf("Post directly, url: %s, headers: %s", $url, json_encode($headers)));
}
return $this->doRequest('POST', $url, false, $scheme, $headers, $body);
}

$realRequestUrl = $this->parseRealRequestUrl($path, $query);
$realRequestHeaders = $this->parseHeaders($headers, $host, $user, $pass, $port, $scheme);
$this->getLog()->info(sprintf("Post through proxy, url: %s, headers: %s", $realRequestUrl, json_encode($realRequestHeaders)));
if ($this->isDebug()) {
$this->getLog()->info(sprintf("Post through proxy, url: %s, headers: %s", $realRequestUrl, json_encode($realRequestHeaders)));
}

return $this->doRequest('POST', $realRequestUrl, true, $scheme, $realRequestHeaders, $body);
}
Expand All @@ -218,13 +226,17 @@ public function put($url, array $headers = null, $body = null): HttpClientRespon
list($scheme, $user, $pass, $host, $port, $path, $query) = $this->parseUrl($url);

if (empty($this->proxy) or $this->isInnerService($host)) {
$this->getLog()->info(sprintf("Put directly, url: %s, headers: %s", $url, json_encode($headers)));
if ($this->isDebug()) {
$this->getLog()->info(sprintf("Put directly, url: %s, headers: %s", $url, json_encode($headers)));
}
return $this->doRequest('PUT', $url, false, $scheme, $headers, $body);
}

$realRequestUrl = $this->parseRealRequestUrl($path, $query);
$realRequestHeaders = $this->parseHeaders($headers, $host, $user, $pass, $port, $scheme);
$this->getLog()->info(sprintf("Put through proxy, url: %s, headers: %s", $realRequestUrl, json_encode($realRequestHeaders)));
if ($this->isDebug()) {
$this->getLog()->info(sprintf("Put through proxy, url: %s, headers: %s", $realRequestUrl, json_encode($realRequestHeaders)));
}

return $this->doRequest('PUT', $realRequestUrl, true, $scheme, $realRequestHeaders, $body);
}
Expand All @@ -242,13 +254,17 @@ public function delete($url, array $headers = null): HttpClientResponse
list($scheme, $user, $pass, $host, $port, $path, $query) = $this->parseUrl($url);

if (empty($this->proxy) or $this->isInnerService($host)) {
$this->getLog()->info(sprintf("Delete directly, url: %s, headers: %s", $url, json_encode($headers)));
if ($this->isDebug()) {
$this->getLog()->info(sprintf("Delete directly, url: %s, headers: %s", $url, json_encode($headers)));
}
return $this->doRequest('DELETE', $url, false, $scheme, $headers, null);
}

$realRequestUrl = $this->parseRealRequestUrl($path, $query);
$realRequestHeaders = $this->parseHeaders($headers, $host, $user, $pass, $port, $scheme);
$this->getLog()->info(sprintf("Delete through proxy, url: %s, headers: %s", $realRequestUrl, json_encode($realRequestHeaders)));
if ($this->isDebug()) {
$this->getLog()->info(sprintf("Delete through proxy, url: %s, headers: %s", $realRequestUrl, json_encode($realRequestHeaders)));
}

return $this->doRequest('DELETE', $realRequestUrl, true, $scheme, $realRequestHeaders, null);
}
Expand Down

0 comments on commit 89563ce

Please sign in to comment.