From 6fa5db10ba075fc0952778c92d18721799c4efe9 Mon Sep 17 00:00:00 2001 From: "hezhiwei.alden@bytedance.com" Date: Tue, 8 Dec 2020 17:55:36 +0800 Subject: [PATCH] =?UTF-8?q?[bugfix]=E4=BF=AE=E5=A4=8D=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=AF=BB=E5=86=99bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/CollectorConfig.php | 2 +- src/FileConsumer.php | 5 +++-- test/FileTester.php | 16 ++++++++++++++++ test/HttpTester.php | 18 ++++++++++++++++++ 4 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 test/FileTester.php create mode 100644 test/HttpTester.php diff --git a/src/CollectorConfig.php b/src/CollectorConfig.php index ff433ae..8f44e7f 100644 --- a/src/CollectorConfig.php +++ b/src/CollectorConfig.php @@ -31,7 +31,7 @@ public static function init_datarangers_collector($config) self::setSAVE(false); self::setSEND(true); } - if (in_array("domain", $config)) { + if (array_key_exists("domain", $config)) { self::setURL($config["domain"] . Constants::$APP_LOG_URL); } else if (self::isSend()) { throw new RangersSDKException(Constants::$DOMAIN_EXCPETION); diff --git a/src/FileConsumer.php b/src/FileConsumer.php index 1306c4e..0be7ede 100644 --- a/src/FileConsumer.php +++ b/src/FileConsumer.php @@ -38,7 +38,6 @@ public function __construct() if ($this->currentIndex != 0) $this->currentIndex++; $this->fullTarget = $this->targetPrefix . $this->targetName . ".log"; $this->currentName = $this->targetName . "." . date("Y.m.d.H", time()); - echo $this->currentIndex, $this->targetPrefix, " ", $this->targetName, " ", $this->fullTarget; $this->output = fopen($this->fullTarget, "a+"); $this->changeOutputStream(); } @@ -103,7 +102,9 @@ public function send($msg) public function close() { if ($this->output == null) return true; - return fclose($this->output); + if(is_resource($this->output)) + return fclose($this->output); + return true; } function __destruct() diff --git a/test/FileTester.php b/test/FileTester.php new file mode 100644 index 0000000..e4a30fa --- /dev/null +++ b/test/FileTester.php @@ -0,0 +1,16 @@ + true, + "logger_file_prefix" => "sdk/log/", + "logger_file_name" => "datarangers.log", + "log_max_bytes" => 1024 * 10 +]); +$rc = new AppEventCollector(new FileConsumer()); +$rc->sendEvent("uuid16981", 10000002, null, ["__profile_set", "php_event"], + [["php_name" => "php", "php_version" => "5.6"], ["php_name" => "php", "php_version" => "5.6"]]); \ No newline at end of file diff --git a/test/HttpTester.php b/test/HttpTester.php new file mode 100644 index 0000000..c34b7c6 --- /dev/null +++ b/test/HttpTester.php @@ -0,0 +1,18 @@ + getenv("HTTP_DOMAIN"), + "send" => true, + "headers" => [ + "Host" => getenv("HTTP_HOST"), + "Content-Type" => "application/json" + ] +]); +$rc = new AppEventCollector(new HttpConsumer()); +$rc->sendEvent("uuid16981", 10000002, null, ["__profile_set", "php_event"], + [["php_name" => "php", "php_version" => "5.6"], ["php_name" => "php", "php_version" => "5.6"]]); \ No newline at end of file