Skip to content

Commit

Permalink
Fix for issue #87, MessageParser is too greedy
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy Baukema committed Oct 17, 2014
1 parent a2949a4 commit d84a448
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
29 changes: 22 additions & 7 deletions library/EngineBlock/Log/Writer/Syslog/MessageParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,32 @@ class EngineBlock_Log_Writer_Syslog_MessageParser
*/
public function parse(array $event)
{
$message = isset($event['message'])
? $this->_normalizeMessage($event['message']) : '';
$message = isset($event['message']) ? $this->_normalizeMessage($event['message']) : '';

preg_match_all(
'/([^\]]*\[[a-zA-Z0-9 ]+\]\[[a-zA-Z0-9 ]+\](\[DUMP[^\]]*\])?)( .*)/',
$message, $matches
'/' .
'('.
'[^\]]*'. // .... (anything but a ]), followed by:
'\[[a-zA-Z0-9 ]+\]'. // [ ... ]
'\[[a-zA-Z0-9 ]+\]'. // [ ... ]
'(\[DUMP[^\]]*\])?'. // Optionally: [DUMP ...]
')'.
'( .*)'. // Anything, starting with a space.
'/',
$message,
$matches
);

if (!isset($matches[1][0]) || !isset($matches[3][0])) {
return array(
'prefix' => 'P[' . time() . '][' . rand(0, 1000000) . ']',
'message' => $message
);
}

return array(
'prefix' => isset($matches[1][0]) ? $matches[1][0] : 'PREFIX REMOVED BY PARSER',
'message' => isset($matches[3][0]) ? $matches[3][0] : 'MESSAGE REMOVED BY PARSER',
'prefix' => $matches[1][0],
'message' => $matches[3][0],
);
}

Expand All @@ -30,7 +45,7 @@ public function parse(array $event)
* Serialized content is prepended with '!FORMAT_[type]', this
* notation is parsed by logparse.sh
*
* @param mixed data structure to dump
* @param string $message structure to dump
* @return string
*/
protected function _normalizeMessage($message)
Expand Down
5 changes: 3 additions & 2 deletions library/EngineBlock/Log/Writer/Syslog/MessageSplitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ public function __construct($messageSplitSize)
* messages and logs them to parent::log(). Message size is determined
* by EngineBlock_Log::MESSAGE_SPLIT_SIZE.
*
* @param string $prefix Message prefix
* @param string $message Message to log
* @param string $prefix Message prefix
* @param string $message Message to log
* @return array
* @throws InvalidArgumentException
*/
public function split($prefix, $message)
{
Expand Down

0 comments on commit d84a448

Please sign in to comment.