diff --git a/src/Facades/Log.php b/src/Facades/Log.php index 443ae443fa4bd414835d519ee00bce12399708db..a6189afae00dcb20fb8b6e51c23a2ee8f91b4099 100644 --- a/src/Facades/Log.php +++ b/src/Facades/Log.php @@ -12,11 +12,10 @@ namespace One\Facades; * @method error($data, $k = 0, $prefix = 'error') static * @method setTraceId($id) static * @method bindTraceId($id) static - * @method flushTraceId() static + * @method flushTraceId($go_id) static * @method getTraceId() static * */ - class Log extends Facade { protected static function getFacadeAccessor() diff --git a/src/Http/Controller.php b/src/Http/Controller.php index 04cd529bb3a4d054f17164891a8c0a1c04e223e6..e8f0d8ac342ffb582875642c7b78da9bd1b93caf 100644 --- a/src/Http/Controller.php +++ b/src/Http/Controller.php @@ -4,6 +4,7 @@ namespace One\Http; use One\Exceptions\HttpException; use One\Facades\Log; +use SebastianBergmann\CodeCoverage\Report\PHP; class Controller { @@ -23,6 +24,8 @@ class Controller */ protected $server; + protected $go_id = -1; + /** * Controller constructor. @@ -31,15 +34,15 @@ class Controller */ public function __construct($request, $response, $server = null) { + $this->go_id = get_co_id(); $this->request = $request; $this->response = $response; $this->server = $server; - } public function __destruct() { - Log::flushTraceId(); + Log::flushTraceId($this->go_id); } /** diff --git a/src/Log.php b/src/Log.php index 0b43ddf50f56d2d9c28684e8905bbbe0c55338a2..2dbbe2308c886634bfdf0e537849f0455e4cf686 100644 --- a/src/Log.php +++ b/src/Log.php @@ -101,7 +101,9 @@ class Log public function setTraceId($id) { - $this->_traceId[get_co_id()] = $id; + $cid = get_co_id(); + $this->_traceId[$cid] = $id; + return $cid; } /** @@ -132,10 +134,9 @@ class Log /** * 请求完成刷新 清除已经关闭的id */ - public function flushTraceId() + public function flushTraceId($id) { if (_CLI_) { - $id = get_co_id(); if (isset($this->_traceId[$id])) { unset($this->_traceId[$id]); } diff --git a/src/Swoole/TcpController.php b/src/Swoole/TcpController.php index f53dd94273672f1a637a14469d460eb6a277afde..7d7edc00d4ab207f38098114bbbdaa1fc1c0399e 100644 --- a/src/Swoole/TcpController.php +++ b/src/Swoole/TcpController.php @@ -28,10 +28,13 @@ class TcpController */ protected $session = null; + protected $go_id = -1; + public function __construct($data, $server) { - $this->data = $data; + $this->go_id = get_co_id(); + $this->data = $data; $this->server = $server; if ($this->data->session_id) { $this->session = new Session(null, $this->data->session_id); @@ -40,7 +43,7 @@ class TcpController public function __destruct() { - Log::flushTraceId(); + Log::flushTraceId($this->go_id); } } \ No newline at end of file diff --git a/src/Swoole/WsController.php b/src/Swoole/WsController.php index 5ad7e959c810ca96b5a3610787d1e4ad0e33ad50..14313313a7500398dfb42c7c47148c9092aed402 100644 --- a/src/Swoole/WsController.php +++ b/src/Swoole/WsController.php @@ -27,16 +27,19 @@ class WsController */ protected $session; + protected $go_id; + public function __construct($frame, $server, $session = null) { - $this->frame = $frame; - $this->server = $server; + $this->go_id = get_co_id(); + $this->frame = $frame; + $this->server = $server; $this->session = $session; } public function __destruct() { - Log::flushTraceId(); + Log::flushTraceId($this->go_id); } } \ No newline at end of file