PHP中把錯誤日志保存在系統(tǒng)日志中(Windows系統(tǒng))
【將錯誤記錄到系統(tǒng)日志中】
在 php.ini 中將 error_log 設(shè)置為:
error_log = syslog
或者在運行時使用 ini_set() 函數(shù)設(shè)置。
【例1】
<?php //關(guān)閉錯誤顯示 ini_set('display_errors', 0); //開啟錯誤日志功能 ini_set('log_errors', 'on'); //設(shè)置錯誤日志的路徑 ini_set('error_log', 'syslog'); //顯示所有錯誤 error_reporting(-1); //記錄錯誤 //通知級別的錯誤 echo $test; //警告 settype($var, 'dee'); //致命錯誤 test();
查看錯誤日志(Windows 系統(tǒng)):
"我的電腦" ---- 右鍵 ----- 管理 ----- 事件查看器 ----- 信息
【例2】通過 openlog() 發(fā)送系統(tǒng)日志
<?php //關(guān)閉錯誤顯示 ini_set('display_errors', 0); //開啟錯誤日志功能 ini_set('log_errors', 'on'); //設(shè)置錯誤日志的路徑 ini_set('error_log', 'syslog'); //顯示所有錯誤 error_reporting(-1); //打開系統(tǒng)日志的連接 openlog('PHP5.3.10', LOG_PID, LOG_SYSLOG); //openlog:Open connection to system logger //發(fā)送日志 syslog(LOG_ERR, 'this is a test of a syslog'.date("Y-m-d H:i:s")); //關(guān)閉系統(tǒng)日志的連接 closelog();
在事件查看器的警告信息中也能看到日志:
相關(guān)文章
在PHP語言中使用JSON和將json還原成數(shù)組的方法
下面小編就為大家?guī)硪黄赑HP語言中使用JSON和將json還原成數(shù)組的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個 參考。一起跟隨小編過來看看吧2016-07-07PHP在線生成二維碼(google api)的實現(xiàn)代碼詳解
本篇文章是對PHP在線生成二維碼(google api)的實現(xiàn)代碼進行了詳細的分析介紹,需要的朋友參考下2013-06-06PHP date()函數(shù)警告: It is not safe to rely on the system解決方法
這篇文章主要介紹了PHP date()函數(shù)警告: It is not safe to rely on the system解決方法,其實就是時區(qū)設(shè)置不正確造成的,本文提供了兩種方法來解決這個問題,需要的朋友可以參考下2014-08-08