//保存日志
public function addLog($msg){
$file_dir = '/data/www/menjin/api/php/application/socket/log/' . date('Y', time()) . '' . date('m', time()).'/';
if (!is_dir($file_dir)) {
mkdir($file_dir, 0777, true);
}
$msg = "[" . date('Y-m-d H:i:s') . "]\t" . $msg . "\n";
$logFile = $file_dir . '/workmanlog' . date('Y-m-d') . '.txt';
if (file_exists($logFile)) {
file_put_contents($logFile, $msg, FILE_APPEND);
} else {
$newLogFile = fopen($logFile, "w");
fwrite($newLogFile, $msg);
fclose($newLogFile);
}
}
PHP保存日志
![](https://img-home.csdnimg.cn/images/20240711042549.png)