Skip to content

Commit

Permalink
read whole logevent
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Semm committed Sep 9, 2012
1 parent 1486b26 commit b3be4c0
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 16 deletions.
11 changes: 4 additions & 7 deletions DataCollector/LogEntry.php
Expand Up @@ -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) {
Expand Down
26 changes: 26 additions & 0 deletions DataCollector/LogEvent.php
@@ -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;
}
}

?>
17 changes: 12 additions & 5 deletions DataCollector/LogFile.php
Expand Up @@ -2,7 +2,7 @@
namespace FS\Log4PhpBundle\DataCollector;

class LogFile {
private $logEntries = array();
private $logEvents = array();
private $logFileName = '';

/**
Expand All @@ -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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion DataCollector/LogReader.php
Expand Up @@ -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));
}
}

Expand Down
1 change: 0 additions & 1 deletion DataCollector/ViewLogsDataCollector.php
Expand Up @@ -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();
}
}
Expand Down
3 changes: 2 additions & 1 deletion Tests/DataCollector/LogEntryTest.php
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion Tests/DataCollector/LogReaderTest.php
Expand Up @@ -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()));
}

/**
Expand Down

0 comments on commit b3be4c0

Please sign in to comment.