mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
文件日志增加max_files参数配置 自动清理多余日志文件
This commit is contained in:
@@ -25,6 +25,7 @@ class File
|
|||||||
'file_size' => 2097152,
|
'file_size' => 2097152,
|
||||||
'path' => LOG_PATH,
|
'path' => LOG_PATH,
|
||||||
'apart_level' => [],
|
'apart_level' => [],
|
||||||
|
'max_files' => 0,
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $writed = [];
|
protected $writed = [];
|
||||||
@@ -48,8 +49,20 @@ class File
|
|||||||
if ($this->config['single']) {
|
if ($this->config['single']) {
|
||||||
$destination = $this->config['path'] . 'single.log';
|
$destination = $this->config['path'] . 'single.log';
|
||||||
} else {
|
} else {
|
||||||
$cli = IS_CLI ? '_cli' : '';
|
$cli = IS_CLI ? '_cli' : '';
|
||||||
$destination = $this->config['path'] . date('Ym') . DS . date('d') . $cli . '.log';
|
|
||||||
|
if ($this->config['max_files']) {
|
||||||
|
$filename = date('Ymd') . $cli . '.log';
|
||||||
|
$files = glob($this->config['path'] . '*.log');
|
||||||
|
|
||||||
|
if (count($files) > $this->config['max_files']) {
|
||||||
|
unlink($files[0]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$filename = date('Ym') . '/' . date('d') . $cli . '.log';
|
||||||
|
}
|
||||||
|
|
||||||
|
$destination = $this->config['path'] . $filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
$path = dirname($destination);
|
$path = dirname($destination);
|
||||||
|
|||||||
Reference in New Issue
Block a user