Log is an indispensable and important function in the project. In PHP, we can use the error_log() function to automatically generate the corresponding log file. This article analyzes the error_log() function to help you understand the error_log() function in PHP.
The example in this article describes how to use the error_log() function in PHP. Share it with everyone for your reference. The specific analysis is as follows:
I encountered a problem today that needed to be debugged, but I could only debug it through log printing, so I used the error_log function.
What needs to be printed is what a server sent to our server. post data
The code is as follows: (Both key and value are printed)
if(!empty($_POST) ){ while (list($key, $val) = each($_POST)) { @error_log("$key => $val", 3,'/tmp/test_post_allstarpay.log' ); } }
error_log has four parameters, mainly the first 3, the first is the log write content, the second One is the log storage method 3, which means storing it in the specified location, and the third one is the storage location
The server uses centos, and tmp has read and write permissions, so it is written to tmp
error_log will automatically generate the corresponding log file, no need to create it manually!
Related recommendations:
#thinkphp log record no file generation
PHP log abbreviation creation function code_php skills
The above is the detailed content of Detailed explanation of the error_log() function in PHP. For more information, please follow other related articles on the PHP Chinese website!