Skip to content

Commit 332214e

Browse files
committed
Add method setEchoLog() to control whether echo http package in cli script
1 parent bc34eb7 commit 332214e

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/BaseClient.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ abstract class BaseClient {
44
protected const SCHEME = 'http', METHOD = 'POST', TIMEOUT = 20, VERIFY_SSL = false, KEEP_ALIVE = true, USE_POOL = true;
55
protected const PARSE_MODE_URL_ENCODE_KV = 1, PARSE_MODE_JSON = 2, PARSE_MODE_RAW = 3; // 普通form格式,json格式,原文。 xml因为需要更多参数,请使用原文格式并在子类中解析
66
protected const PARSE_POST = self::PARSE_MODE_URL_ENCODE_KV, PARSE_GET = self::PARSE_MODE_URL_ENCODE_KV;
7+
private static $_echo_log_on = true;
8+
/**
9+
* BaseClient在cli模式下默认会输出请求响应内容到标准输出
10+
* @param bool $on
11+
*/
12+
public static function setEchoLog(bool $on = false): void {
13+
self::$_echo_log_on = $on;
14+
}
715
/**
816
*
917
* @var \Swlib\Saber\Request
@@ -188,7 +196,7 @@ protected function getLogDir(): string {
188196
return $dir;
189197
}
190198
protected function writeLog(string &$log_string): void {
191-
if (\Swango\Environment::getWorkingMode()->isInCliScript()) {
199+
if (self::$_echo_log_on && \Swango\Environment::getWorkingMode()->isInCliScript()) {
192200
if (strlen($log_string) > 4096) {
193201
echo substr($log_string, 0, 4096) . "\n\n";
194202
} else {

0 commit comments

Comments
 (0)