| 14 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
#使用命名空間qbpwcf
|
|
|
4 |
namespace qbpwcf;
|
|
|
5 |
|
|
|
6 |
#匯入外部套件
|
|
|
7 |
include("../allInOneForJson.php");
|
|
|
8 |
|
|
|
9 |
/*
|
|
|
10 |
|
|
|
11 |
#提示要測試的套件
|
|
|
12 |
#echo "<hr>logs::parseLog2sessionWithMultiMsgStartSupport & logs::filterMsgPackWithMultiKeywordSupport - testCase 2<br>";
|
|
|
13 |
|
|
|
14 |
#如果有 $_POST["lineStart"] 存在
|
|
|
15 |
if(isset($_POST["lineStart"]))
|
|
|
16 |
{
|
|
|
17 |
|
|
|
18 |
#函式說明:
|
|
|
19 |
#解析讀取到的log內容,分段成數個訊息(可以有多種)儲存到session陣列中並回傳完整的訊息部分.
|
|
|
20 |
#回傳結果:
|
|
|
21 |
#$result["status"],狀態,"true"或"false".
|
|
|
22 |
#$result["error"],錯誤訊息陣列.
|
|
|
23 |
#$result["function"],當前函式的名稱.
|
|
|
24 |
#$result["argu"],使用的參數.
|
|
|
25 |
#$result["content"],陣列,每個有關鍵字的訊息陣列.
|
|
|
26 |
#$result["lineNum"],數字,當前行數.
|
|
|
27 |
#必填參數:
|
|
|
28 |
#$conf["path"],log檔案的路徑與名稱.
|
|
|
29 |
$conf["path"]="logsT/Devcom-9497.log";
|
|
|
30 |
#$conf["msgStart"],字串陣列,用來識別訊息開頭的開頭關鍵字,支援多種訊息的開頭.
|
|
|
31 |
#$conf["msgStart"]=array("i UdpS, ".date('n')."/".date('j'),"i TcpSvr, ".date('n')."/".date('j'));
|
|
|
32 |
$conf["msgStart"]=array("i UdpS, 1/30","i TcpSvr, 1/30");
|
|
|
33 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
34 |
$conf["fileArgu"]=__FILE__;
|
|
|
35 |
#可省略參數:
|
|
|
36 |
#$conf["sessionName"],字串,儲存log的session變數key.
|
|
|
37 |
#$conf["sessionName"]="";
|
|
|
38 |
#$conf["line2start"],字串,log從第幾列開始,預設為總行數減去linesPerTime+1.
|
|
|
39 |
$conf["line2start"]=$_POST["lineStart"];
|
|
|
40 |
#$conf["linesPerTime"],字串,一次最多讀取幾列,預設爲10列.
|
|
|
41 |
$conf["linesPerTime"]="10";
|
|
|
42 |
$parseLog2sessionWithMultiMsgStartSupport=logs::parseLog2sessionWithMultiMsgStartSupport($conf);
|
|
|
43 |
unset($conf);
|
|
|
44 |
|
|
|
45 |
#如果執行錯誤
|
|
|
46 |
if($parseLog2sessionWithMultiMsgStartSupport["status"]==="false"){
|
|
|
47 |
|
|
|
48 |
#印出結果
|
|
|
49 |
var_dump($parseLog2sessionWithMultiMsgStartSupport);
|
|
|
50 |
|
|
|
51 |
#結束執行
|
|
|
52 |
exit;
|
|
|
53 |
|
|
|
54 |
}#if end
|
|
|
55 |
|
|
|
56 |
#函式說明:
|
|
|
57 |
#解析多個訊息陣列,尋找符合其中一組關鍵字出現的訊息,並回傳之.
|
|
|
58 |
#回傳結果:
|
|
|
59 |
#$result["status"],狀態,"true"或"false".
|
|
|
60 |
#$result["error"],錯誤訊息陣列.
|
|
|
61 |
#$result["function"],當前函式的名稱.
|
|
|
62 |
#$result["argu"],使用的參數.
|
|
|
63 |
#$result["content"],陣列,有開頭關鍵字出現的訊息陣列.
|
|
|
64 |
#必填參數:
|
|
|
65 |
#$conf["msgs"],陣列,由多個訊息陣列組成.
|
|
|
66 |
$conf["msgs"]=$parseLog2sessionWithMultiMsgStartSupport["content"];
|
|
|
67 |
#$conf["keyWords"],二維陣列,每個關鍵字.
|
|
|
68 |
$conf["keyWords"]=array(array("2","3","E","B"),array("i"," ","T","c","p","S","v","r"));
|
|
|
69 |
#$conf["keyWordsAddr"],二維陣列,關鍵字的位置是第幾個.
|
|
|
70 |
$conf["keyWordsAddr"]=array(array("21","22","24","25"),array("0","1","2","3","4","5","6","7"));
|
|
|
71 |
#可省略參數:
|
|
|
72 |
#無
|
|
|
73 |
$filterMsgPackWithMultiKeywordSupport=logs::filterMsgPackWithMultiKeywordSupport($conf);
|
|
|
74 |
unset($conf);
|
|
|
75 |
|
|
|
76 |
#如果執行錯誤
|
|
|
77 |
if($filterMsgPackWithMultiKeywordSupport["status"]==="false"){
|
|
|
78 |
|
|
|
79 |
#印出結果
|
|
|
80 |
var_dump($filterMsgPackWithMultiKeywordSupport);
|
|
|
81 |
|
|
|
82 |
#結束執行
|
|
|
83 |
exit;
|
|
|
84 |
|
|
|
85 |
}#if end
|
|
|
86 |
|
|
|
87 |
#初始化要印出的內容
|
|
|
88 |
$result=array();
|
|
|
89 |
|
|
|
90 |
#初始化儲存lineArray內容
|
|
|
91 |
$lineArray=array();
|
|
|
92 |
|
|
|
93 |
#針對每個訊息陣列
|
|
|
94 |
foreach($filterMsgPackWithMultiKeywordSupport["content"] as $res){
|
|
|
95 |
|
|
|
96 |
#函式說明:
|
|
|
97 |
#將多個一維陣列串聯起來,key從0開始排序.
|
|
|
98 |
#回傳的結果:
|
|
|
99 |
#$result["status"],"true"表執行正常,"false"代表執行不正常.
|
|
|
100 |
#$result["error"],錯誤訊息陣列.
|
|
|
101 |
#$result["function"],當前執行的函數.
|
|
|
102 |
#$result["content"],合併好的一維陣列.
|
|
|
103 |
#必填的參數
|
|
|
104 |
#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
|
|
|
105 |
$conf["inputArray"]=array($lineArray,$res);
|
|
|
106 |
#可省略的參數:
|
|
|
107 |
#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
|
|
|
108 |
$conf["allowRepeat"]="false";
|
|
|
109 |
$mergeArray=arrays::mergeArray($conf);
|
|
|
110 |
unset($conf);
|
|
|
111 |
|
|
|
112 |
$lineArray=$mergeArray["content"];
|
|
|
113 |
|
|
|
114 |
}#foreach end
|
|
|
115 |
|
|
|
116 |
#設置要印出的內容
|
|
|
117 |
$result["lines"]=$lineArray;
|
|
|
118 |
|
|
|
119 |
#設置新的欄數
|
|
|
120 |
$result["id"]["lineStart"]=$parseLog2sessionWithMultiMsgStartSupport["lineNum"];
|
|
|
121 |
|
|
|
122 |
#印出 json
|
|
|
123 |
echo json_encode($result);
|
|
|
124 |
|
|
|
125 |
}#if end
|
|
|
126 |
|
|
|
127 |
*/
|
|
|
128 |
|
|
|
129 |
?>
|