Home >Backend Development >PHP Tutorial >Save the error log in the system log in PHP_PHP tutorial

Save the error log in the system log in PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:49:141028browse

Save the error log in the system log in PHP

This article mainly introduces how to save the error log in the system log in PHP (Windows system). This article explains the settings For the method and viewing method, friends in need can refer to it

【Record errors to the system log】

Set error_log in php.ini to:

Copy the code. The code is as follows:

 error_log = syslog

Or use the ini_set() function to set it at runtime.

【Example 1】

 ?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

//关闭错误显示

ini_set('display_errors', 0);

//开启错误日志功能

ini_set('log_errors', 'on');

//设置错误日志的路径

ini_set('error_log', 'syslog');

//显示所有错误

error_reporting(-1);

 

//记录错误

//通知级别的错误

echo $test;

//警告

settype($var, 'dee');

//致命错误

test();

1

2

3
4
5
6
7

8

9

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

//关闭错误显示

ini_set('display_errors', 0);

//开启错误日志功能

ini_set('log_errors', 'on');

//设置错误日志的路径

ini_set('error_log', 'syslog');

//显示所有错误

error_reporting(-1);

 

//打开系统日志的连接

openlog('PHP5.3.10', LOG_PID, LOG_SYSLOG); //openlog:Open connection to system logger

//发送日志

syslog(LOG_ERR, 'this is a test of a syslog'.date("Y-m-d H:i:s"));

//关闭系统日志的连接

closelog();

10

11
12
13
14 15

1617
//Close error display ini_set('display_errors', 0); //Enable error log function ini_set('log_errors', 'on'); //Set the path of the error log
ini_set('error_log', 'syslog'); //Show all errors error_reporting(-1); //Record errors //Notification level error echo $test; //Warning settype($var, 'dee'); //Fatal error test();
View error log (Windows system):  "My Computer" ---- Right click ----- Management ----- Event Viewer ----- Information [Example 2] Send system logs through openlog()  ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
The log can also be seen in the warning message in the event viewer: http://www.bkjia.com/PHPjc/1020271.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1020271.htmlTechArticleSave the error log in the system log in PHP. This article mainly introduces the saving of the error log in the system log in PHP. In the log (Windows system), this article explains the setting method and viewing method, which requires...
Statement:
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