Skip to content

Commit

Permalink
3.1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
kiss291323003 committed Jan 15, 2019
1 parent 644ea7a commit 90e39bf
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 19 deletions.
8 changes: 5 additions & 3 deletions bin/easyswoole
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Swoole\Table;
use EasySwoole\EasySwoole\Config as GlobalConfig;

class TcpService
class ConsoleService
{
/*
* 下划线开头表示不希望用户使用
Expand Down
12 changes: 6 additions & 6 deletions src/Console/DefaultCommand/Auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
]);
Expand Down
2 changes: 1 addition & 1 deletion src/Console/TcpController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Core.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
45 changes: 40 additions & 5 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;
}
}
2 changes: 1 addition & 1 deletion src/SysConst.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 90e39bf

Please sign in to comment.