我正在远程调试以前的程序员使用CodeIgniter框架构建的API。我用其他PHP MVC框架编程,但我以前从未构建过API(也没有使用CodeIgniter),并且调试变量总是像echo, var_dump, print_r一样容易,……或者直接使用框架的日志命令。
现在,我没有显示错误和日志的页面(或者我有吗?),我尝试了log_message, error_log和put_file_contents,没有任何运气!它只运行第一个日志命令,但第二个不运行!在我的模型我有以下功能:
public function processcontacts($data) {
error_log(json_encode($data), 3, "~/logs/processcontacts_data.txt");
$countryCode = $data["countryCode"];
error_log(json_encode($countryCode), 3, "~/logs/processcontacts_countryCode.txt");
$isContact = array();
$isNotContact = array();
foreach ($data as $key => $value) {
$value->phone = str_replace(" ", "", $value->phone);
$value->name = str_replace(" undefined", "", $value->name);
$value->name = str_replace(" Undefined", "", $value->name);
$query = $this->db->get_where('appusers', array(
'id' => $this->getMyId($value->phone, $countryCode)
)
);
if ($query->num_rows() > 0) {
$row = $query->row();
$value->country = $row->country;
if ($row->photoapproved == 1) {
$value->photo = $row->photo;
}
$value->token = $row->token;
array_push($isContact, $value);
} else {
array_push($isNotContact, $value);
}
}
$returner = array();
$returner["isMember"] = $isContact;
$returner["isNotMember"] = $isNotContact;
return json_encode($returner);
}
我有两个error_log(或put_file_contents),但只有一个显示,之后什么也没有!任何可能的是什么可能是这个原因和如何跟踪它?
CodeIgniter有一些内置的错误记录功能:
-
让/application/logs文件夹可写
-
In
/application/config/config.php
set:$config['log_threshold'] = 1;
有多个级别的日志记录,像这样:
/*
|--------------------------------------------------------------------------
| Error Logging Threshold
|--------------------------------------------------------------------------
|
| You can enable error logging by setting a threshold over zero. The
| threshold determines what gets logged. Threshold options are:
|
| 0 = Disables logging, Error logging TURNED OFF
| 1 = Error Messages (including PHP errors)
| 2 = Debug Messages
| 3 = Informational Messages
| 4 = All Messages
|
| You can also pass an array with threshold levels to show individual error types
|
| array(2) = Debug Messages, without Error Messages
|
| For a live site you'll usually only enable Errors (1) to be logged otherwise
| your log files will fill up very fast.
|
*/
$config['log_threshold'] = 4;
有关更多参考,请参阅CodeIgniter错误处理
配置设置中的日志文件名需要以"/"的可写访问权限目录。
希望这对你有帮助!
原来我没有配置正确的php.ini文件!需要修改的是'../apache2/..'
然而,我真的发现Postman是一个调试远程API的好工具,所以我想在这里指出来引起注意。(感谢@ xpuc70)