摘要:日志的记录时发现问题的最直观的方法,记录日志的方法也很多,因人而异;
方法一(自己封装的方法):
/**
* 生成日志
* @return str
* @author Tom
* @Time 2018/03/06 15:33
*/
function logInfo($info, $address=null, $fileName = 'log'){
$debugInfo = debug_backtrace();
$message = date('Y-m-d H:i:s').PHP_EOL.$info.PHP_EOL;
$message .= '['.$debugInfo[0]['file'].'] line'.$debugInfo[0]['line'].PHP_EOL;
file_put_contents(dirname(__FILE__).$address.$fileName.'-'.date('Y-m-d').'.log', $message, FILE_APPEND);
return true;
}
# 接收调用
$info = file_get_contents("php://input");
logInfo($info,$address);
方法二(PHP的函数):
参考:
1、php error_log记录日志的使用方法和配置
2、菜鸟教程
个人比较喜欢以下的方法记录(因为可以直接设置保存文件的路径):
error_log("搞砸了!", 3, "/usr/local/errors.log"); //发送到指定的文件中,linux的记录地址
error_log("搞砸了!", 3, "D:/php-7.2.5-nts-x64/php_log/php_error.log ");//windows的记录地址
error_log(print_r($this->getLastSql(), 1), 3, '/tmp/tom');