From b3be4c04806078b61fd5af2678ed4fe0f70b265f Mon Sep 17 00:00:00 2001 From: Florian Semm Date: Sun, 9 Sep 2012 13:16:35 +0200 Subject: [PATCH] read whole logevent --- DataCollector/LogEntry.php | 11 ++++------- DataCollector/LogEvent.php | 26 +++++++++++++++++++++++++ DataCollector/LogFile.php | 17 +++++++++++----- DataCollector/LogReader.php | 2 +- DataCollector/ViewLogsDataCollector.php | 1 - Tests/DataCollector/LogEntryTest.php | 3 ++- Tests/DataCollector/LogReaderTest.php | 2 +- 7 files changed, 46 insertions(+), 16 deletions(-) create mode 100644 DataCollector/LogEvent.php diff --git a/DataCollector/LogEntry.php b/DataCollector/LogEntry.php index f59f00b..99443f0 100644 --- a/DataCollector/LogEntry.php +++ b/DataCollector/LogEntry.php @@ -11,13 +11,10 @@ class LogEntry { * @param \DOMNode $node */ public function __construct(\DOMNode $node) { - if ($event = $this->getLogEvent($node)) { - $this->logger = $this->logAttributes($event, 'logger'); - $this->level = $this->logAttributes($event, 'level'); - $this->timestamp = $this->logAttributes($event, 'timestamp'); - } - - $this->message = $this->getLogMessage($event); + $this->logger = $this->logAttributes($node, 'logger'); + $this->level = $this->logAttributes($node, 'level'); + $this->timestamp = $this->logAttributes($node, 'timestamp'); + $this->message = $this->getLogMessage($node); } private function logAttributes($event, $attributeName) { diff --git a/DataCollector/LogEvent.php b/DataCollector/LogEvent.php new file mode 100644 index 0000000..582ccb4 --- /dev/null +++ b/DataCollector/LogEvent.php @@ -0,0 +1,26 @@ +childNodes) { + foreach ($node->childNodes as $logevent) { + if ($logevent instanceof \DOMText) { + continue; + } + + $this->logEntries[] = new LogEntry($logevent); + } + + + } + } + + public function getLogEntries() { + return $this->logEntries; + } +} + +?> \ No newline at end of file diff --git a/DataCollector/LogFile.php b/DataCollector/LogFile.php index 2e2da1e..aa33bf2 100644 --- a/DataCollector/LogFile.php +++ b/DataCollector/LogFile.php @@ -2,7 +2,7 @@ namespace FS\Log4PhpBundle\DataCollector; class LogFile { - private $logEntries = array(); + private $logEvents = array(); private $logFileName = ''; /** @@ -13,17 +13,24 @@ public function __construct($logFileName) { } /** - * @param LogEntry $entry + * @param LogEntry $event */ - public function addLogEntry(LogEntry $entry) { - $this->logEntries[] = $entry; + public function addLogEvent(LogEvent $event) { + $this->logEvents[] = $event; } /** * @return array */ public function getLogEntries() { - return $this->logEntries; + $logEntries = array(); + + foreach ($this->logEvents as $event) { + $logEntries = array_merge($logEntries, $event->getLogEntries()); + } + + + return $logEntries; } /** diff --git a/DataCollector/LogReader.php b/DataCollector/LogReader.php index f8383b0..b8659aa 100644 --- a/DataCollector/LogReader.php +++ b/DataCollector/LogReader.php @@ -43,7 +43,7 @@ public function __construct($logFile) { private function parseXML(\DOMDocument $dom, LogFile $logfile) { foreach ($this->getChildLogEntries($dom) as $logEntryXml) { if (preg_match('/log4php:eventSet/', $logEntryXml->getNodePath())) { - $logfile->addLogEntry(new LogEntry($logEntryXml)); + $logfile->addLogEvent(new LogEvent($logEntryXml)); } } diff --git a/DataCollector/ViewLogsDataCollector.php b/DataCollector/ViewLogsDataCollector.php index 4fd4b7b..ceebc18 100644 --- a/DataCollector/ViewLogsDataCollector.php +++ b/DataCollector/ViewLogsDataCollector.php @@ -19,7 +19,6 @@ public function collect(Request $request, Response $response, \Exception $except $logs = array(); foreach ($this->logFiles as $logFile) { $logReader = new LogReader($logFile); - $this->data['logs'][] = $logReader->getLogFile(); } } diff --git a/Tests/DataCollector/LogEntryTest.php b/Tests/DataCollector/LogEntryTest.php index 5cbba46..1d911f6 100644 --- a/Tests/DataCollector/LogEntryTest.php +++ b/Tests/DataCollector/LogEntryTest.php @@ -18,8 +18,9 @@ private function getLogContent($filename) { $dom->loadXML($logContent); $eventSet = $dom->getElementsByTagName('root')->item(0)->childNodes->item(1); + $logEvent = $eventSet->childNodes->item(1); - return $eventSet; + return $logEvent; } public function testGetAllLogInformations_ValidInputLogContent() { diff --git a/Tests/DataCollector/LogReaderTest.php b/Tests/DataCollector/LogReaderTest.php index a0b992f..9970c77 100644 --- a/Tests/DataCollector/LogReaderTest.php +++ b/Tests/DataCollector/LogReaderTest.php @@ -16,7 +16,7 @@ private function getLogFile($filename) { public function testGetLogEntries_ValidInputLogContent() { $log = new LogReader($this->getLogFile('info.xml')); - $this->assertEquals(2, count($log->getLogFile()->getLogEntries())); + $this->assertEquals(4, count($log->getLogFile()->getLogEntries())); } /**