Permalink
Browse files

read whole logevent

  • Loading branch information...
1 parent 1486b26 commit b3be4c04806078b61fd5af2678ed4fe0f70b265f Florian Semm committed Sep 9, 2012
@@ -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) {
@@ -0,0 +1,26 @@
+<?php
+namespace FS\Log4PhpBundle\DataCollector;
+
+class LogEvent {
+ private $logEntries = array();
+
+ public function __construct(\DOMNode $node) {
+ if ($node->childNodes) {
+ foreach ($node->childNodes as $logevent) {
+ if ($logevent instanceof \DOMText) {
+ continue;
+ }
+
+ $this->logEntries[] = new LogEntry($logevent);
+ }
+
+
+ }
+ }
+
+ public function getLogEntries() {
+ return $this->logEntries;
+ }
+}
+
+?>
@@ -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;
}
/**
@@ -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));
}
}
@@ -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();
}
}
@@ -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() {
@@ -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()));
}
/**

0 comments on commit b3be4c0

Please sign in to comment.