改名
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
namespace Snowflake\Error;
|
||||
|
||||
|
||||
use Exception;
|
||||
use HttpServer\Http\Context;
|
||||
use Snowflake\Core\Json;
|
||||
use Snowflake\Exception\ComponentException;
|
||||
@@ -34,26 +35,15 @@ class LoggerProcess extends Process
|
||||
/**
|
||||
* @param \Swoole\Process $process
|
||||
* @throws ComponentException
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function message(\Swoole\Process $process)
|
||||
{
|
||||
$message = Json::decode($process->read());
|
||||
if (!empty($message)) {
|
||||
$fileName = 'server-' . date('Y-m-d') . '.log';
|
||||
$dirName = 'log/' . (empty($method) ? 'app' : $method);
|
||||
Snowflake::writeFile($this->getDirName($message), $message[0], FILE_APPEND);
|
||||
|
||||
Snowflake::writeFile(storage($fileName, $dirName), $message[0], FILE_APPEND);
|
||||
|
||||
$files = new \DirectoryIterator(storage(null, $dirName) . '/*.log');
|
||||
if ($files->getSize() >= 15) {
|
||||
$command = 'find ' . storage(null, $dirName) . '/ -mtime +15 -name "*.log" -exec rm -rf {} \;';
|
||||
if (Context::inCoroutine())
|
||||
Coroutine\System::exec($command);
|
||||
else
|
||||
\shell_exec($command);
|
||||
}
|
||||
var_dump($message);
|
||||
$this->checkLogFile($message[1]);
|
||||
}
|
||||
|
||||
Coroutine\System::sleep(1);
|
||||
@@ -61,4 +51,29 @@ class LoggerProcess extends Process
|
||||
$this->message($process);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $message
|
||||
* @return string
|
||||
* @throws Exception
|
||||
*/
|
||||
private function getDirName($message): string
|
||||
{
|
||||
return storage('server-' . date('Y-m-d') . '.log', $message[1]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $dirName
|
||||
* @throws Exception
|
||||
*/
|
||||
private function checkLogFile($dirName)
|
||||
{
|
||||
$files = new \DirectoryIterator(storage(null, $dirName) . '/*.log');
|
||||
if ($files->getSize() < 15) {
|
||||
return;
|
||||
}
|
||||
Coroutine\System::exec('find ' . storage(null, $dirName) . '/ -mtime +15 -name "*.log" -exec rm -rf {} \;');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user