2024 年日本 PHP 研討會

SeasLog::analyzerDetail

(PECL seaslog >=1.1.6)

SeasLog::analyzerDetail透過等級、日誌路徑、關鍵字、起始位置、限制和順序取得日誌詳細資訊

說明

public static SeasLog::analyzerDetail(
    字串 $level,
    字串 $log_path = ?,
    字串 $key_word = ?,
    整數 $start = ?,
    整數 $limit = ?,
    int $order = ?
): mixed

SeasLog 使用系統管線執行 `grep -ai '{level}' | grep -ai '{key_word}' | sed -n '{start},{limit}'p` 並將結果以陣列形式返回 PHP。

參數

level

字串。日誌訊息級別。

log_path

字串。日誌訊息路徑。

key_word

字串。日誌訊息的搜尋關鍵字。

start

整數。預設值為 `1`。

limit

整數。預設值為 `20`。

order

整數。預設值為 SEASLOG_DETAIL_ORDER_ASC。亦可參考

回傳值

以陣列形式返回結果。

注意事項:

當 `start` 和 `limit` 不為 NULL 且在 Windows 系統下時,SeasLog 會拋出異常,訊息為 'Param start and limit don't support Windows'(參數 start 和 limit 不支援 Windows)。

範例

範例 #1 SeasLog::analyzerDetail() 範例

<?php

$result1
= SeasLog::analyzerDetail(SEASLOG_ERROR);

//使用 `logger` 和 `key_word`
$result2 = SeasLog::analyzerDetail(SEASLOG_ERROR,'test/logger/','neeke');

//使用 `start` 和 `limit`
$result3 = SeasLog::analyzerDetail(SEASLOG_ERROR,'test/logger/','neeke',1,2);

var_dump($result1,$result2,$result3);
?>

上述範例將輸出類似以下的內容

array(20) {
  [0]=>
  string(93) "2018-07-09 12:52:53 | ERROR | 12247 | 5b42ea2580e51 | 1531111973.528 | log message from neeke"
  [1]=>
  string(93) "2018-07-09 12:52:54 | ERROR | 12256 | 5b42ea26d6657 | 1531111974.878 | log message from neeke"
  [2]=>
  string(93) "2018-07-09 12:52:55 | ERROR | 12265 | 5b42ea277b8d4 | 1531111975.506 | log message from neeke"
  [3]=>
  string(104) "2018-07-09 12:52:55 | ERROR | 12274 | 5b42ea27db5dc | 1531111975.898 | log message from the other people"
...
}

array(3) {
  [0]=>
  string(93) "2018-07-09 12:52:53 | ERROR | 12247 | 5b42ea2580e51 | 1531111973.528 | log message from neeke"
  [1]=>
  string(93) "2018-07-09 12:52:54 | ERROR | 12256 | 5b42ea26d6657 | 1531111974.878 | log message from neeke"
  [2]=>
  string(93) "2018-07-09 12:52:55 | ERROR | 12265 | 5b42ea277b8d4 | 1531111975.506 | log message from neeke"
}

array(2) {
  [0]=>
  string(93) "2018-07-09 12:52:53 | ERROR | 12247 | 5b42ea2580e51 | 1531111973.528 | log message from neeke"
  [1]=>
  string(93) "2018-07-09 12:52:54 | ERROR | 12256 | 5b42ea26d6657 | 1531111974.878 | log message from neeke"
}

參見

新增註記

使用者貢獻的註記

此頁面沒有使用者貢獻的註記。
To Top