PHP中把錯誤記錄檔儲存在系統日誌中_PHP教程

來源:互聯網
上載者:User

PHP中把錯誤記錄檔儲存在系統日誌中


  這篇文章主要介紹了PHP中把錯誤記錄檔儲存在系統日誌中(Windows系統),本文講解了設定方法和查看方法,需要的朋友可以參考下

  【將錯誤記錄到系統日誌中】

  在 php.ini 中將 error_log 設定為:

  複製代碼 代碼如下:

  error_log = syslog

  或者在運行時使用 ini_set() 函數設定。

  【例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();

  查看錯誤記錄檔(Windows 系統):

  "我的電腦" ---- 右鍵 ----- 管理 ----- 事件檢視器 ----- 資訊

  【例2】通過 openlog() 發送系統日誌

  ?

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();

  在事件檢視器的警告資訊中也能看到日誌:

http://www.bkjia.com/PHPjc/1020271.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1020271.htmlTechArticlePHP中把錯誤記錄檔儲存在系統日誌中 這篇文章主要介紹了PHP中把錯誤記錄檔儲存在系統日誌中(Windows系統),本文講解了設定方法和查看方法,需要...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.