1.利用error_log
http://www.w3schools.com/php/func_error_log.asp
PHP error_log() Function
Complete PHP Error Reference
Definition and Usage
The error_log() function sends an error to the server error log, a file or a remote destination.This funtion returns TRUE on success, or FALSE on failure.
Syntax
error_log(error,type,destination,headers)
Parameter | Description |
---|---|
error | Required. The error message to log |
type | Optional. Specifies the error log type. Possible log types:
|
destination | Optional. Specifies where to send the error message. The value of this parameter depends on the value of the "type" parameter |
headers | Optional. Only used if the "type" parameter is "1". Specifies additional headers, like From, Cc, and Bcc. The additional headers should be separated with a CRLF (\r\n). Note: When sending an email, it must contain a From header. This can be set with this parameter or in the php.ini file. |
Example
The following example sends an e-mail with a custom error:
<?php
$test=2;
if ($test>1)
{
error_log("A custom error has been triggered",
1,"someone@example.com","From: webmaster@example.com");
}
?>
$test=2;
if ($test>1)
{
error_log("A custom error has been triggered",
1,"someone@example.com","From: webmaster@example.com");
}
?>
A custom error has been triggered
Complete PHP Error Reference
2.自製 function
http://richile0819.blogspot.tw/2012/07/php-write-log-phplog.html
function write_log($str,$status,$data_array) //傳入資料夾名 想寫近的狀態 資料
{
$textname = $str.date("Ymd").".txt"; //檔名 filename
$URL = "log/".$str."/"; //路徑 Path
if(!is_dir($URL)) // 路徑中的$str 資料夾是否存在 Folder exists in the path
mkdir($URL,0700);
$URL .= $textname; //完整路徑與檔名 The full path and filename
$time = $str.$status.":".date("H:i:s"); //時間 Time
$writ_tmp = '';
foreach ($data_array as $key => $value) //將陣列資料讀出 To read array data
{
$writ_tmp .= ",".$key."=".$value;
}
$write_data = $time.$writ_tmp."\n";
$fileopen = fopen($URL, "a+");
fseek($fileopen, 0);
fwrite($fileopen,$write_data); //寫資料進去 write data
fclose($fileopen);
}
沒有留言:
張貼留言