PHP logs errors by daily date
Release: 2016-07-25 09:02:24
Original
1400 people have browsed it
File 1: [error.class.php] Rewrite error processing and perform file-type log output. There will be two times, the first is Greenwich time, the second is Beijing time, followed by error information, when used Just include this file. Of course, you can also modify the file format according to your own needs. For example, you can add a mail function later to send it to the email...
File 2: [test.php] test file, which contains error statements for testing.
- function exceptionHandler(){
- error_reporting(E_ALL ^ E_NOTICE);
- date_default_timezone_set('Etc/GMT-8'); //Set the time zone
-
- ini_set('display_errors',0); / /Record errors to the log
- ini_set('error_log','D:\'.date('Y-m-d').'_weblog.txt');
- ini_set('log_errors',1); //Enable error log Record
- ini_set('ignore_repeated_errors',1); //Do not repeatedly record error messages that appear on the same line of code in the same file.
- $user_defined_err = error_get_last();
- if($user_defined_err['type'] > 0)
- {
- switch($user_defined_err['type']){
- case 1:
- $user_defined_errType = 'fatal runtime Error (E_ERROR)';
- break;
- case 2:
- $user_defined_errType = 'Non-fatal runtime error (E_WARNING)';
- break;
- case 4:
- $user_defined_errType = 'Compile-time syntax parsing error (E_PARSE)' ;
- break;
- case 8:
- $user_defined_errType = 'Runtime prompt (E_NOTICE)';
- break;
- case 16:
- $user_defined_errType = 'PHP internal error (E_CORE_ERROR)';
- break;
- case 32:
- $ user_defined_errType = 'PHP internal warning (E_CORE_WARNING)';
- break;
- case 64:
- $user_defined_errType = 'Zend script engine internal error (E_COMPILE_ERROR)';
- break;
- case 128:
- $user_defined_errType = 'Zend script engine internal warning (E_COMPILE_WARNING)';
- break;
- case 256:
- $user_defined_errType = 'User-defined error (E_USER_ERROR)';
- break;
- case 512:
- $user_defined_errType = 'User-defined warning (E_USER_WARNING)';
- break;
- case 1024:
- $user_defined_errType = 'User-defined prompt (E_USER_NOTICE)';
- break;
- case 2048:
- $user_defined_errType = 'Code prompt (E_STRICT)';
- break;
- case 4096:
- $user_defined_errType = 'Yes Caught fatal error (E_RECOVERABLE_ERROR)';
- break;
- case 8191:
- $user_defined_errType = 'All error warnings (E_ALL)';
- break;
- default:
- $user_defined_errType = 'Unknown type';
- break;
- }
- $msg = sprintf('%s %s %s %s %s',date("Y-m-d H:i:s"),$user_defined_errType,$user_defined_err['message'],$user_defined_err['file'],$ user_defined_err['line']);
- error_log($msg,0);
- }
- }
-
- register_shutdown_function('exceptionHandler');
- ?>
Copy code
- //File 2: [test.php]
- include('error.class.php');
- echo $_COOKIE[' aaaaadfa']; //If this cookie does not exist, an error will be generated and is used for testing
- echo $_SESSION['aaaaadfa']; //If this session does not exist, an error will be generated and is used for testing
- ? >
-
Copy code
|
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31