Skip to content

Commit

Permalink
Change file structure. Probably when multiple threads are writing the…
Browse files Browse the repository at this point in the history
…y are rarely generating garbage data. This change should help ignore those garbage lines.
  • Loading branch information
mantas-done committed Dec 21, 2023
1 parent 48e8c17 commit 5138899
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
6 changes: 1 addition & 5 deletions src/LogParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@ public static function parse($type, $group)
$data = \File::get($path);
$data = trim($data);

$pattern = '/^([^\s]+) ([^\s]+) ([^\s]+) ([^\s]+) ([^\s]+)/m';
if ($group === 'user') {
$pattern = '/^([^\s]+) ([^\s]+) ([^\s]+) ([^\s]+) ([^\s]+) ([^\s]+)/m';
}
$pattern = '/^\|([^\s]+) ([^\s]+) ([^\s]+) ([^\s]+) ([^\s]+) ([^\s]+)\|$/m';
preg_match_all($pattern, $data, $matches, PREG_SET_ORDER);

foreach ($matches as $record) {
// $timestamp, $duration, $sql_duration, $type, $name, $ip

Expand Down
2 changes: 1 addition & 1 deletion src/LogWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ private static function formatData($time, $duration, $sql_time, $type, $name, $u
$string_data .= " $user";
}

return $string_data . "\n";
return '|' . $string_data . "|\n";
}
}

0 comments on commit 5138899

Please sign in to comment.