What is the usage of error_log in PHP?
The error_log function in PHP is used to record error messages or other information in the server’s error log file. It takes three parameters: the error message (the text to be recorded), the log type (specifying the type of message, such as ERROR, WARNING, INFO, etc.), and an optional target file path (the file path where the log will be written). If no target file path is specified, the log will default to being written in PHP’s error log file. Here is an example usage:
$error_message = "An error occurred!";
error_log($error_message, 3, "/var/log/php_errors.log"); // 将错误消息记录到指定的文件中
In the example above, the error_log function records the error message “An error occurred!” to the specified file “/var/log/php_errors.log”. The second parameter 3 specifies the error message type as ERROR. If no log type parameter is specified, the default ERROR type will be used.