feat: 修改日志处理类以支持不同级别的日志文件
This commit is contained in:
parent
4b2c385b8b
commit
cf8c5e8f64
@ -16,11 +16,23 @@ return [
|
||||
'default' => [
|
||||
'handlers' => [
|
||||
[
|
||||
'class' => Monolog\Handler\RotatingFileHandler::class,
|
||||
// 'class' => Monolog\Handler\RotatingFileHandler::class,
|
||||
// 'constructor' => [
|
||||
// runtime_path() . '/logs/'.date('Ym').'/.log',
|
||||
// 2048,
|
||||
// Monolog\Logger::INFO,
|
||||
// true,
|
||||
// 0755
|
||||
// ],
|
||||
// 'formatter' => [
|
||||
// 'class' => Monolog\Formatter\LineFormatter::class,
|
||||
// 'constructor' => [null, 'Y-m-d H:i:s', true,true],
|
||||
// ],
|
||||
'class' => \support\log\MonologExtendHandler::class,
|
||||
'constructor' => [
|
||||
runtime_path() . '/logs/'.date('Ym').'/.log',
|
||||
null,
|
||||
2048,
|
||||
Monolog\Logger::INFO,
|
||||
Monolog\Logger::DEBUG,
|
||||
true,
|
||||
0755
|
||||
],
|
||||
|
@ -19,8 +19,10 @@ return [
|
||||
'class' => \support\log\MonologExtendHandler::class,
|
||||
'constructor' => [
|
||||
'redis-queue',
|
||||
7, //$maxFiles
|
||||
Monolog\Logger::NOTICE,
|
||||
2048,
|
||||
Monolog\Logger::DEBUG,
|
||||
true,
|
||||
0755
|
||||
],
|
||||
'formatter' => [
|
||||
'class' => Monolog\Formatter\LineFormatter::class,
|
||||
|
@ -1,11 +1,15 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: hjl
|
||||
* Date: 2023/6/21
|
||||
* Time: 07:25
|
||||
*/
|
||||
|
||||
namespace support\log;
|
||||
|
||||
use Monolog\Handler\StreamHandler;
|
||||
use Monolog\Logger;
|
||||
use Monolog\DateFormatter;
|
||||
use DateTime;
|
||||
|
||||
class MonologExtendHandler extends StreamHandler
|
||||
{
|
||||
@ -13,6 +17,7 @@ class MonologExtendHandler extends StreamHandler
|
||||
protected bool $mustRotate;
|
||||
protected string $runtimeLogPath;
|
||||
protected string|null $channelDirName;
|
||||
protected $level;
|
||||
|
||||
/**
|
||||
* @param string $channelDirName 日志通道路径
|
||||
@ -28,6 +33,7 @@ class MonologExtendHandler extends StreamHandler
|
||||
{
|
||||
$this->runtimeLogPath = runtime_path() . '/logs/';
|
||||
$this->channelDirName = $channelDirName;
|
||||
$this->level=$level;
|
||||
$dateDir = date('Ym').'/';
|
||||
$filename = date('d') .'.log';
|
||||
$fullFilePath = empty($channelDirName) ? $this->runtimeLogPath . $dateDir .$filename : $this->runtimeLogPath . $this->channelDirName . '/' . $dateDir . $filename;
|
||||
@ -97,12 +103,16 @@ class MonologExtendHandler extends StreamHandler
|
||||
}
|
||||
$dateDir = date('Ym') . '/';
|
||||
$logBasePath = empty($this->channelDirName) ? $this->runtimeLogPath . $dateDir : $this->runtimeLogPath . $this->channelDirName . '/' . $dateDir;
|
||||
$filename = date('d').'.log';
|
||||
if($this->level==200){
|
||||
$filename = date('d').'.log';
|
||||
}else{
|
||||
$filename = date('d').'_error.log';
|
||||
}
|
||||
$fullLogFilename = $logBasePath . $filename;
|
||||
// archive latest file
|
||||
clearstatcache(true, $fullLogFilename);
|
||||
if (file_exists($fullLogFilename)) {
|
||||
$target = $logBasePath. date('Y-m') . '_' . $filename;
|
||||
$target = $logBasePath. $filename;
|
||||
rename($fullLogFilename, $target);
|
||||
}else{
|
||||
if (!is_dir($logBasePath))
|
||||
|
Loading…
x
Reference in New Issue
Block a user