|
@@ -219,4 +219,86 @@ line;
|
|
|
fclose($file);
|
|
|
}
|
|
|
|
|
|
+ public function testFilter()
|
|
|
+ {
|
|
|
+ $start_time = '2021-12-28 15:22:00';
|
|
|
+ $end_time = '2021-12-28 15:41:00';
|
|
|
+
|
|
|
+ $files = ['45' => 'xaj'];
|
|
|
+ $prefix = BASE_DATA_PATH . "/log/pdlog";
|
|
|
+ foreach ($files as $path => $name) {
|
|
|
+ $input = "{$prefix}/{$path}/{$name}";
|
|
|
+ $outpath = "{$prefix}/{$path}";
|
|
|
+ $this->filter_time($input,$outpath,$start_time,$end_time);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function filter_time($input_file,$outpath,$start_time,$end_time)
|
|
|
+ {
|
|
|
+ $start = strtotime($start_time);
|
|
|
+ $end = strtotime($end_time);
|
|
|
+
|
|
|
+ $reader = function ($fp) use ($start, $end)
|
|
|
+ {
|
|
|
+ while(!feof($fp))
|
|
|
+ {
|
|
|
+ $line = fgets($fp);
|
|
|
+ $ret = preg_match('/\[cordispatcher[\s]+(?P<pid>[\d]+)-[\d]+[\s]+(?P<time>[\d-]+[\s]{1}[\d:]+)[\s]{1}/u', $line, $matches);
|
|
|
+ if ($ret)
|
|
|
+ {
|
|
|
+ $time = strtotime($matches['time']);
|
|
|
+ if ($time < $start) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ elseif($time > $end) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ yield $line;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+
|
|
|
+ $filter_time = function ($line)
|
|
|
+ {
|
|
|
+ $ret = preg_match('/\[cordispatcher[\s]+(?P<pid>[\d]+)-[\d]+[\s]+(?P<time>[\d-]+[\s]{1}[\d:]+)[\s]{1}/u', $line, $matches);
|
|
|
+ if ($ret) {
|
|
|
+ $pid = intval($matches['pid']);
|
|
|
+ return $pid;
|
|
|
+ }
|
|
|
+
|
|
|
+ return 0;
|
|
|
+ };
|
|
|
+ $pid_fp = [];
|
|
|
+ $spliter = function ($pid,$line) use ($outpath,$pid_fp)
|
|
|
+ {
|
|
|
+ if(array_key_exists($pid,$pid_fp)) {
|
|
|
+ $fp = $pid_fp[$pid];
|
|
|
+ } else {
|
|
|
+ $name = "{$outpath}/{$pid}.log";
|
|
|
+ $fp = fopen($name,'w');
|
|
|
+ $pid_fp[$pid] = $fp;
|
|
|
+ }
|
|
|
+
|
|
|
+ fwrite($fp,$line);
|
|
|
+ };
|
|
|
+
|
|
|
+ $input = fopen($input_file,'r');
|
|
|
+
|
|
|
+ $lines = $reader($input);
|
|
|
+ foreach ($lines as $line)
|
|
|
+ {
|
|
|
+ $pid = $filter_time($line);
|
|
|
+ if($pid > 0) {
|
|
|
+ $spliter($pid,$line);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ fclose($input);
|
|
|
+ foreach ($pid_fp as $pid => $fp) {
|
|
|
+ fclose($fp);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|