1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-26 20:52:44 +08:00

1.优化日志清理

2.增加cli下带色输出
This commit is contained in:
xiaochong0302 2023-07-03 16:23:11 +08:00
parent b519fd4d6d
commit 30ece511df
3 changed files with 18 additions and 35 deletions

View File

@ -19,7 +19,6 @@ class CleanLogTask extends Task
$this->cleanHttpLog();
$this->cleanSqlLog();
$this->cleanListenLog();
$this->cleanCaptchaLog();
$this->cleanWeChatLog();
$this->cleanMailLog();
$this->cleanSmsLog();
@ -96,18 +95,6 @@ class CleanLogTask extends Task
$this->whitelist[] = $type;
}
/**
* 清理验证码服务日志
*/
protected function cleanCaptchaLog()
{
$type = 'captcha';
$this->cleanLog($type, 7);
$this->whitelist[] = $type;
}
/**
* 清理点播服务日志
*/
@ -268,13 +255,12 @@ class CleanLogTask extends Task
* 清理其它日志
*
* @param int $keepDays
* @return mixed
*/
protected function cleanOtherLog($keepDays = 7)
{
$files = glob(log_path() . "/*.log");
if (!$files) return false;
if (!$files) return;
foreach ($files as $file) {
$name = str_replace(log_path() . '/', '', $file);
@ -287,9 +273,9 @@ class CleanLogTask extends Task
if (strtotime($today) - strtotime($date) >= $keepDays * 86400) {
$deleted = unlink($file);
if ($deleted) {
echo "delete {$file} success" . PHP_EOL;
$this->successPrint("remove {$file} success");
} else {
echo "delete {$file} failed" . PHP_EOL;
$this->errorPrint("remove {$file} failed");
}
}
}
@ -300,13 +286,12 @@ class CleanLogTask extends Task
*
* @param string $prefix
* @param int $keepDays 保留天数
* @return mixed
*/
protected function cleanLog($prefix, $keepDays)
{
$files = glob(log_path() . "/{$prefix}-*.log");
if (!$files) return false;
if (!$files) return;
foreach ($files as $file) {
$date = substr($file, -14, 10);
@ -314,9 +299,9 @@ class CleanLogTask extends Task
if (strtotime($today) - strtotime($date) >= $keepDays * 86400) {
$deleted = unlink($file);
if ($deleted) {
echo "------ delete {$file} success ------" . PHP_EOL;
$this->successPrint("remove {$file} success");
} else {
echo "------ delete {$file} failed -------" . PHP_EOL;
$this->errorPrint("remove {$file} failed");
}
}
}

View File

@ -11,5 +11,17 @@ use App\Traits\Service as ServiceTrait;
class Task extends \Phalcon\Cli\Task
{
use ServiceTrait;
protected function successPrint($text)
{
echo "\033[32m {$text} \033[0m" . PHP_EOL;
}
protected function errorPrint($text)
{
echo "\033[31m {$text} \033[0m" . PHP_EOL;
}
}

View File

@ -76,20 +76,6 @@ class PublicController extends Controller
return $this->jsonSuccess(['site' => $site]);
}
/**
* @Get("/captcha/info", name="api.public.captcha_info")
*/
public function captchaInfoAction()
{
$service = new AppService();
$captcha = $service->getSettings('captcha');
unset($captcha['secret_key']);
return $this->jsonSuccess(['captcha' => $captcha]);
}
/**
* @Get("/payment/info", name="api.public.payment_info")
*/