1. Log the error to the specified file and configure the process as follows
* 1). Log_errors=on
* 2). Error_log=/tmp/php_error.log
1. Log error logs using the Error_log () function
Error_log (' error message to be logged! ’);
Header' content-type:text/html; Charset=utf-8 ');//Turn on all error reportsError_reporting (-1);//Set time zoneIni_set (' Date.timezone ',' PRC ');//Disable page display errorsIni_set (' Display_errors ',0);//Turn on logging functionIni_set (' Log_errors ',1);//Set the location where the error log is savedIni_set (' Error_log ','/tmp/custom_error.log ');//Ignore duplicate errorsIni_set (' Ignore_repeated_errors ',' on ');//Ignore duplicate source of errorIni_set (' Ignore_repeated_source ',' on '); Error_log (' I'm going to record you in my custom error log '. Date (' y-m-d h:i:s ', Time ())); Trigger_error (' Trigger_error-----I'm going to record you in my system error log '. Date (' y-m-d h:i:s ', time ()), e_user_notice); Settype ($var,' King ');
2. Log errors to the system log
* 1. ini_set(‘error_log‘, ‘syslog‘);
Common
Method One//Turn on all error reportsError_reporting (-1);//Disable page display errorsIni_set (' Display_errors ',0);//Turn on logging functionIni_set (' Log_errors ',1);//Set the location where the error log is saved------(System log)Ini_set (' Error_log ',' syslog ');//Ignore duplicate errorsIni_set (' Ignore_repeated_errors ',' on ');//Ignore duplicate source of errorIni_set (' Ignore_repeated_source ',' on ');//Error_log (' error_log-----I'm going to record you in my system error log '. Date (' y-m-d h:i:s ', Time ()));Trigger_error (' Trigger_error-----I'm going to record you in my system error log '. Date (' y-m-d h:i:s ', time ()), e_user_notice);//Settype ($var, ' King ');Method Two//==================== not =========================== for security.//Open a link to the system logOpenlog (' PHP5.6.0 ', Log_pid, Log_syslog); SYSLOG (Log_err,' This is a test syslog '. Date (' y-m-d h:i:s ', Time ())); Closelog ();
2. Send the error log via email
* 1. Error_log (' msg ', 1, mail_addr);
The second parameter is set to 1
* * bool
error_log (String $message
[, int $message _type = 0
[, stri ng $destination
[, String $extra _headers
]])
message应该被记录的错误信息。message_type设置错误应该发送到何处。可能的信息类型有以下几个:error_log() 日志类型0 message 发送到 PHP 的系统日志,使用 操作系统的日志机制或者一个文件,取决于 error_log 指令设置了什么。 这是个默认的选项。1 message 发送到参数 destination 设置的邮件地址。 第四个参数 extra_headers 只有在这个类型里才会被用到。2 不再是一个选项。3 messagemessage 不会默认被当做新的一行。4 message1 的时候使用。 该信息类型使用了 mail() 的同一个内置函数。
//Turn on all error reportsError_reporting (-1);//Disable page display errorsIni_set (' Display_errors ',0);//Turn on logging functionIni_set (' Log_errors ',1);//Ignore duplicate errorsIni_set (' Ignore_repeated_errors ',' on ');//Ignore duplicate source of errorIni_set (' Ignore_repeated_source ',' on ');//Set the second parameter to 1 to send error log messages using mailError_log (' error_log-----I'm going to record you in my system error log '. Date (' y-m-d h:i:s ', time ()),1,' [email protected] ');
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
2.PHP How to log errors and send errors