This commit is contained in:
2021-02-23 11:15:47 +08:00
parent 646a52f17e
commit 3831d7e9f0
2 changed files with 34 additions and 15 deletions
+18 -1
View File
@@ -14,6 +14,8 @@ use Snowflake\Abstracts\Component;
use Snowflake\Abstracts\Config;
use Snowflake\Core\Json;
use Snowflake\Snowflake;
use Swoole\Coroutine;
use Swoole\Coroutine\Channel;
use Swoole\Process;
use Throwable;
@@ -28,6 +30,21 @@ class Logger extends Component
public int $worker_id;
private Channel $channel;
public function init()
{
$this->channel = new Channel(5000);
Coroutine::create(function () {
while ($message = $this->channel->pop(-1)) {
echo $message;
}
});
}
/**
* @param $message
* @param string $method
@@ -124,7 +141,7 @@ class Logger extends Component
*/
public function output($message)
{
echo $message;
$this->channel->push($message);
}