Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge pull request zendframework/zendframework#5882 from Martin-P/iss…
Browse files Browse the repository at this point in the history
…ue-5881

Allow setting formatter for Zend\Log\Writer\Db via config options
  • Loading branch information
weierophinney committed Mar 5, 2014
158 parents cadc7b4 + 77fde49 + 0d988ee + 49bc0b3 + 6faf2bb + df3a849 + ee5efcb + 2ee5d16 + bcb4d03 + a5c61e2 + 57ffceb + a6fa26b + 9d36595 + bf0040c + 71b1a95 + 5619ba3 + c093ab0 + de13946 + 04b025f + 0933607 + 34ed3ed + 83f6472 + db74e8c + 7b75da1 + bb4c48f + 9fa3c05 + 139c0b1 + a587eef + 7a782f4 + 39cb2e2 + 31f8c80 + a9b7779 + de058f6 + 67b97f6 + 40d86d0 + b5234cc + 17b4e13 + 8af24aa + 1a9df55 + 2c85c99 + 5557fac + fe78a35 + f6430c3 + 6041a1e + 86b9031 + 674bd75 + 67a1bfb + 4d4dd8b + c655082 + dbb18b2 + 97a9134 + 80367df + 98d5255 + 7946c9f + ea67c13 + 44df0b2 + 38e090d + 7af74e7 + 8b311b1 + e2c2b94 + 51601cb + dcc1eaf + 6f4b805 + a30a64f + ee7347d + 8b04bfe + b487f00 + ecdfdf6 + d8cde75 + b7a33bb + 65ecb58 + 571d938 + 625a786 + 6fe4efc + f94838d + 76607e3 + 492076c + 17b56b8 + c5509fe + e0fa433 + 7d74e99 + 309136e + f1dd38a + 7be533f + 6a618c2 + 3a454e3 + f66ca80 + f1bebf2 + 850249d + 674d7ba + 597ff82 + ae87c49 + fb156fb + 9c474de + 1a75c72 + 47d1cd2 + a937ea3 + 4219922 + 49e380f + 5903df6 + 7a9d632 + 2ef7274 + b606220 + a09c5c7 + 21afa5c + 8faa67f + 1731915 + efa1bb3 + 5576455 + 86d3ae8 + de3fd70 + 398a3c4 + 5c56554 + 7ad896f + fa91c9b + 1372a45 + a0c8737 + e368d53 + 462b1f7 + 79675fe + a8104b9 + 91ed9d0 + b1d1358 + 6a0c90c + 5e4258f + 239c0d0 + b457c76 + a2533a4 + beb6598 + 79d0f46 + 1519723 + 5084e3b + ce75f80 + e5fd689 + 6744e82 + 6cb64b8 + 03c6da8 + 7dcfd8f + a18fe5d + 5e5ada1 + 4112f92 + 975bb98 + a8af3df + ef19f19 + 8e92f40 + da1eb0c + fe5af05 + bba7d3a + 91ae243 + a6e4ac0 + 937e129 + d074ac7 + d4876c1 + c35719b + 8250024 + 805fd63 + 5c3d30d + 4f53f56 commit 0313de9
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/Writer/AbstractWriter.php
Expand Up @@ -306,6 +306,26 @@ public function setFormatter($formatter, array $options = null)
return $this;
}

/**
* Get formatter
*
* @return Formatter\FormatterInterface
*/
public function getFormatter()
{
return $this->formatter;
}

/**
* Check if the writer has a formatter
*
* @return bool
*/
public function hasFormatter()
{
return $this->formatter instanceof Formatter\FormatterInterface;
}

/**
* Set convert write errors to exception flag
*
Expand Down
5 changes: 3 additions & 2 deletions src/Writer/Db.php
Expand Up @@ -12,7 +12,6 @@
use Traversable;
use Zend\Db\Adapter\Adapter;
use Zend\Log\Exception;
use Zend\Log\Formatter;
use Zend\Log\Formatter\Db as DbFormatter;

class Db extends AbstractWriter
Expand Down Expand Up @@ -87,7 +86,9 @@ public function __construct($db, $tableName = null, array $columnMap = null, $se
$this->separator = $separator;
}

$this->setFormatter(new DbFormatter());
if (!$this->hasFormatter()) {
$this->setFormatter(new DbFormatter());
}
}

/**
Expand Down
30 changes: 30 additions & 0 deletions test/Writer/AbstractTest.php
Expand Up @@ -102,4 +102,34 @@ public function testConstructorWithOptions()
$this->assertInstanceOf('Zend\Log\Filter\Priority', $filters[1]);
$this->assertEquals(3, $this->readAttribute($filters[1], 'priority'));
}

/**
* @covers Zend\Log\Writer\AbstractWriter::getFormatter
*/
public function testFormatterDefaultsToNull()
{
$this->assertNull($this->_writer->getFormatter());
}

/**
* @covers Zend\Log\Writer\AbstractWriter::getFormatter
* @covers Zend\Log\Writer\AbstractWriter::setFormatter
*/
public function testCanSetFormatter()
{
$formatter = new SimpleFormatter;
$this->_writer->setFormatter($formatter);
$this->assertSame($formatter, $this->_writer->getFormatter());
}

/**
* @covers Zend\Log\Writer\AbstractWriter::hasFormatter
*/
public function testHasFormatter()
{
$this->assertFalse($this->_writer->hasFormatter());

$this->_writer->setFormatter(new SimpleFormatter);
$this->assertTrue($this->_writer->hasFormatter());
}
}
6 changes: 6 additions & 0 deletions test/Writer/DbTest.php
Expand Up @@ -242,5 +242,11 @@ public function testConstructWithOptions()
$filters = self::readAttribute($writer, 'filters');
$this->assertCount(1, $filters);
$this->assertEquals($filter, $filters[0]);

$registeredFormatter = self::readAttribute($writer, 'formatter');
$this->assertSame($formatter, $registeredFormatter);

$registeredDb = self::readAttribute($writer, 'db');
$this->assertSame($this->db, $registeredDb);
}
}

0 comments on commit 0313de9

Please sign in to comment.