Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Dec 11, 2013
1 parent 7b56572 commit 5f8cb60
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library/Zend/Log/Formatter/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function format($event)
{
foreach ($event as $key => $value) {
// Keep extra as an array
if ('extra' === $key) {
if ('extra' === $key && is_array($value)) {
$event[$key] = self::format($value);
} else {
$event[$key] = $this->normalize($value);
Expand Down
16 changes: 16 additions & 0 deletions tests/ZendTest/Log/Formatter/BaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,20 @@ public function testFormatNoInfiniteLoopOnSelfReferencingArrayValues()

$this->assertEquals($outputExpected, $formatter->format($event));
}

public function testFormatNonArrayExtrakey()
{
$formatter = new BaseFormatter();

$event = array(
'message' => 'Hi',
'extra' => '',
);
$outputExpected = array(
'message' => 'Hi',
'extra' => '',
);

$this->assertEquals($outputExpected, $formatter->format($event));
}
}
19 changes: 19 additions & 0 deletions tests/ZendTest/Log/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,4 +366,23 @@ public function testExceptionHandler()
$this->assertEquals($expectedEvent['file'], $event['extra']['file'], 'Unexpected file');
}
}

public function testLogExtraArrayKey()
{
$stream = fopen("php://memory", "r");
$options = array(
'writers' => array(
array(
'name' => 'stream',
'options' => array(
'stream' => $stream
),
),
),
);
$logger = new Logger($options);

$this->assertInstanceOf('Zend\Log\Logger', $logger->info('Hi', array('extra' => '')));
fclose($stream);
}
}

0 comments on commit 5f8cb60

Please sign in to comment.