diff --git a/bin/easyswoole b/bin/easyswoole index 844445fc..6efa255d 100644 --- a/bin/easyswoole +++ b/bin/easyswoole @@ -215,8 +215,10 @@ switch ($mainCommand){ foreach ($ips as $eth => $val){ Install::showTag('ip@'.$eth, $val); } - Install::showTag('worker num', $conf->getConf('MAIN_SERVER.SETTING.worker_num')); - Install::showTag('task worker num', $conf->getConf('MAIN_SERVER.SETTING.task_worker_num')); + $data = $conf->getConf('MAIN_SERVER.SETTING'); + foreach ($data as $key => $datum){ + Install::showTag($key, (string)$datum); + } $user = $conf->getConf('MAIN_SERVER.SETTING.user'); if(empty($user)){ $user = get_current_user(); @@ -232,7 +234,7 @@ switch ($mainCommand){ Install::showTag('swoole version', phpversion('swoole')); Install::showTag('php version', phpversion()); Install::showTag('easy swoole', \EasySwoole\EasySwoole\SysConst::EASYSWOOLE_VERSION); - Install::showTag('run mode', $mode); + Install::showTag('develop/produce', $mode); Install::showTag('temp dir', EASYSWOOLE_TEMP_DIR); Install::showTag('log dir', EASYSWOOLE_LOG_DIR); \EasySwoole\EasySwoole\Core::getInstance()->start(); diff --git a/src/Console/TcpService.php b/src/Console/ConsoleService.php similarity index 99% rename from src/Console/TcpService.php rename to src/Console/ConsoleService.php index c696b7fc..ea44dc8d 100644 --- a/src/Console/TcpService.php +++ b/src/Console/ConsoleService.php @@ -20,7 +20,7 @@ use Swoole\Table; use EasySwoole\EasySwoole\Config as GlobalConfig; -class TcpService +class ConsoleService { /* * 下划线开头表示不希望用户使用 diff --git a/src/Console/DefaultCommand/Auth.php b/src/Console/DefaultCommand/Auth.php index e5e5e040..ebc95bbf 100644 --- a/src/Console/DefaultCommand/Auth.php +++ b/src/Console/DefaultCommand/Auth.php @@ -8,10 +8,10 @@ namespace EasySwoole\EasySwoole\Console\DefaultCommand; +use EasySwoole\Component\TableManager; use EasySwoole\EasySwoole\Config; use EasySwoole\EasySwoole\Console\CommandInterface; -use EasySwoole\EasySwoole\Console\TcpService; -use EasySwoole\EasySwoole\Swoole\Memory\TableManager; +use EasySwoole\EasySwoole\Console\ConsoleService; use EasySwoole\Socket\Bean\Caller; use EasySwoole\Socket\Bean\Response; @@ -34,24 +34,24 @@ public function exec(Caller $caller, Response $response) $fd = $caller->getClient()->getFd(); $args = $caller->getArgs(); if (Config::getInstance()->getConf('CONSOLE.AUTH') == array_shift($args)) { - TableManager::getInstance()->get(TcpService::$__swooleTableName)->set($fd, [ + TableManager::getInstance()->get(ConsoleService::$__swooleTableName)->set($fd, [ 'isAuth' => 1, 'tryTimes' => 0 ]); $response->setMessage('auth succeed'); } else { - $info = TableManager::getInstance()->get(TcpService::$__swooleTableName)->get($fd); + $info = TableManager::getInstance()->get(ConsoleService::$__swooleTableName)->get($fd); if (!empty($info)) { if ($info['tryTimes'] > 5) { $response->setStatus(Response::STATUS_RESPONSE_AND_CLOSE); } else { - TableManager::getInstance()->get(TcpService::$__swooleTableName)->set($fd, [ + TableManager::getInstance()->get(ConsoleService::$__swooleTableName)->set($fd, [ 'isAuth' => 0, 'tryTimes' => $info['tryTimes'] + 1 ]); } } else { - TableManager::getInstance()->get(TcpService::$__swooleTableName)->set($fd, [ + TableManager::getInstance()->get(ConsoleService::$__swooleTableName)->set($fd, [ 'isAuth' => 0, 'tryTimes' => 1 ]); diff --git a/src/Console/TcpController.php b/src/Console/TcpController.php index d67a3bdb..2955b528 100644 --- a/src/Console/TcpController.php +++ b/src/Console/TcpController.php @@ -21,7 +21,7 @@ function onRequest(?string $actionName): bool $authKey = Config::getInstance()->getConf('CONSOLE.AUTH'); //如果开启了权限验证 if (!empty($authKey)) { - $info = TableManager::getInstance()->get(TcpService::$__swooleTableName)->get($fd); + $info = TableManager::getInstance()->get(ConsoleService::$__swooleTableName)->get($fd); //如果是执行鉴权命令 if ($actionName == 'auth') { return true; diff --git a/src/Core.php b/src/Core.php index 3057d78e..aaef8427 100644 --- a/src/Core.php +++ b/src/Core.php @@ -14,7 +14,7 @@ use EasySwoole\Component\Di; use EasySwoole\Component\Singleton; use EasySwoole\EasySwoole\AbstractInterface\Event; -use EasySwoole\EasySwoole\Console\TcpService; +use EasySwoole\EasySwoole\Console\ConsoleService; use EasySwoole\EasySwoole\Crontab\Crontab; use EasySwoole\EasySwoole\Swoole\EventHelper; use EasySwoole\EasySwoole\Swoole\EventRegister; @@ -121,7 +121,7 @@ function createServer() $this->registerDefaultCallBack(ServerManager::getInstance()->getSwooleServer(),$conf['SERVER_TYPE']); EasySwooleEvent::mainServerCreate(ServerManager::getInstance()->getMainEventRegister()); //创建主服务后,创建Tcp子服务 - (new TcpService(Config::getInstance()->getConf('CONSOLE'))); + (new ConsoleService(Config::getInstance()->getConf('CONSOLE'))); return $this; } diff --git a/src/Logger.php b/src/Logger.php index 69aaa045..0046c026 100644 --- a/src/Logger.php +++ b/src/Logger.php @@ -10,8 +10,9 @@ use EasySwoole\Component\Singleton; -use EasySwoole\EasySwoole\Console\TcpService; +use EasySwoole\EasySwoole\Console\ConsoleService; use EasySwoole\Trace\AbstractInterface\LoggerInterface; +use EasySwoole\Trace\Bean\Location; class Logger implements LoggerInterface { @@ -23,15 +24,49 @@ function __construct(LoggerInterface $logger) $this->logger = $logger; } - public function log(string $str, $logCategory, int $timestamp = null) + public function log(string $str, $logCategory = 'default', int $timestamp = null):?string { // TODO: Implement log() method. - $this->logger->log($str,$logCategory,$timestamp); + $str = $this->logger->log($str,$logCategory,$timestamp); + if(Config::getInstance()->getConf('CONSOLE.PUSH_LOG')){ + ConsoleService::push($str); + } + return $str; } - public function console(string $str, $category = null, $saveLog = true) + public function logWithLocation(string $str,$logCategory = 'default',int $timestamp = null):?string + { + $location = $this->getLocation(); + $str = "[file:{$location->getFile()}][line:{$location->getLine()}]{$str}"; + return $this->log($str,$logCategory); + } + + public function console(string $str, $category = null, $saveLog = true):?string + { + // TODO: Implement console() method. + $str = $this->logger->console($str,$category,$saveLog); + if(Config::getInstance()->getConf('CONSOLE.PUSH_LOG')){ + ConsoleService::push($str); + } + return $str; + } + + public function consoleWithLocation(string $str, $category = null, $saveLog = true):?string { // TODO: Implement console() method. - $this->logger->console($str,$category,$saveLog); + $location = $this->getLocation(); + $str = "[file:{$location->getFile()}][line:{$location->getLine()}]{$str}"; + return $this->console($str,$category,$saveLog); + } + + private function getLocation():Location + { + $location = new Location(); + $debugTrace = debug_backtrace(); + array_shift($debugTrace); + $caller = array_shift($debugTrace); + $location->setLine($caller['line']); + $location->setFile($caller['file']); + return $location; } } \ No newline at end of file diff --git a/src/SysConst.php b/src/SysConst.php index 53924b81..f5051c56 100644 --- a/src/SysConst.php +++ b/src/SysConst.php @@ -11,7 +11,7 @@ class SysConst { - const EASYSWOOLE_VERSION = '3.1.8'; + const EASYSWOOLE_VERSION = '3.1.9'; const LOGGER_HANDLER = 'LOGGER_HANDLER'; const ERROR_HANDLER = 'ERROR_HANDLER'; const TRIGGER_HANDLER = 'TRIGGER_HANDLER';