feat : common redis cache and common logger

This commit is contained in:
2025-09-14 15:58:45 +08:00
parent 48ad2ebd1b
commit 0db9995c19
15 changed files with 640 additions and 14 deletions

91
app/Lib/Log/Logger.php Normal file
View File

@@ -0,0 +1,91 @@
<?php
namespace App\Lib\Log;
use Hyperf\Logger\LoggerFactory;
use Psr\Log\LoggerInterface;
/**
* Log类分组调用
* config/autoload/logger.php 在前面的配置文件中添加分组 在这个文件中添加方法(也可以直接调用 channel('分组名称'))
*/
class Logger
{
/**
* @var LoggerFactory
*/
protected LoggerFactory $loggerFactory;
/**
* @param LoggerFactory $loggerFactory
*/
public function __construct(LoggerFactory $loggerFactory)
{
$this->loggerFactory = $loggerFactory;
}
/**
* @return LoggerInterface
*/
public function default(): LoggerInterface
{
return $this->loggerFactory->get('default','default');
}
/**
* @return LoggerInterface
*/
public function error(): LoggerInterface
{
return $this->loggerFactory->get('error','error');
}
/**
* @return LoggerInterface
*/
public function request(): LoggerInterface
{
return $this->loggerFactory->get('request','request');
}
/**
* @return LoggerInterface
*/
public function cron(): LoggerInterface
{
return $this->loggerFactory->get('cron','cron');
}
/**
* @return LoggerInterface
*/
public function payment(): LoggerInterface
{
return $this->loggerFactory->get('payment','payment');
}
/**
* @return LoggerInterface
*/
public function audit(): LoggerInterface
{
return $this->loggerFactory->get('audit','audit');
}
/**
* @return LoggerInterface
*/
public function cache(): LoggerInterface
{
return $this->loggerFactory->get('cache','cache');
}
/**
* @param string $channel
* @return LoggerInterface
*/
public function channel(string $channel): LoggerInterface
{
return $this->loggerFactory->get($channel, $channel);
}
}