...
|
...
|
@@ -33,7 +33,7 @@ class Log { |
|
|
*/
|
|
|
public function __construct()
|
|
|
{
|
|
|
$this->setFilename();
|
|
|
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -71,12 +71,8 @@ class Log { |
|
|
* @author:dc
|
|
|
* @time 2023/3/14 11:11
|
|
|
*/
|
|
|
private function setFilename($filename=null){
|
|
|
if($filename){
|
|
|
private function setFilename($filename){
|
|
|
$this->filename[md5($filename)] = $filename;
|
|
|
}else{
|
|
|
$this->filename['default'] = $filename = LOG_PATH.'/'.app()->nowDate().'.error.log';
|
|
|
}
|
|
|
|
|
|
// 创建目录
|
|
|
if(!is_dir(dirname($filename))){
|
...
|
...
|
@@ -86,28 +82,35 @@ class Log { |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @return array
|
|
|
*/
|
|
|
public function getFilename($key=null): string
|
|
|
{
|
|
|
return $this->filename[$key]??LOG_PATH.'/'.date('Y-m-d').'.error.log';
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 写入日志
|
|
|
* @author:dc
|
|
|
* @time 2023/3/14 10:45
|
|
|
*/
|
|
|
public function write(){
|
|
|
|
|
|
foreach ($this->filename as $key=>$fn){
|
|
|
if(!empty($this->message[$key])){
|
|
|
$fo = @fopen($fn,'a');
|
|
|
foreach ($this->message as $key=>$msg){
|
|
|
|
|
|
$fo = @fopen($this->getFilename($key),'a');
|
|
|
if(!$fo){
|
|
|
$fo = @fopen($this->getFilename(),'a');
|
|
|
}
|
|
|
if($fo){
|
|
|
foreach ($this->message[$key] as &$log){
|
|
|
foreach ($msg as $log){
|
|
|
@fwrite($fo,$log.PHP_EOL);
|
|
|
}
|
|
|
@fclose($fo);
|
|
|
}
|
|
|
|
|
|
$log = null;
|
|
|
unset($log);
|
|
|
|
|
|
$this->message[$key] = null;
|
|
|
unset($this->message[$key]);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
...
|
...
|
|